package engine.newUi
{
	import com.greensock.TweenLite;
	
	import engine.GameData;
	import engine.control.TurnPapersViewGroup;
	import engine.data.BindManage;
	import engine.data.ModelLocator;
	import engine.data.ObjectData;
	import engine.data.Record;
	import engine.data.ResPath;
	import engine.data.View;
	import engine.data.ViewObject;
	import engine.display.newAttack.action.effect.PointPlayLite;
	import engine.display.newAttack.vo.PetVo;
	import engine.flag.ResourcesPath;
	import engine.logic.McPool;
	import engine.logic.MenuListManager;
	import engine.logic.ShowDamageNum;
	import engine.logic.event.LogicEvent;
	import engine.net.datatype.WString;
	import engine.net.event.CustomMsgEvent;
	import engine.net.messages.CustomToClientFlag;
	import engine.net.messages.CustomToServerFlag;
	import engine.net.mgr.SystemSender;
	import engine.scene.SceneManager;
	import engine.scene.player.BasePlayerModel;
	import engine.tip.TipsMainLogic;
	import engine.ui.AlertUI;
	import engine.ui.UIManage;
	import engine.util.FilterUtil;
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.geom.Point;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.utils.Timer;
	
	import newx.com.ResManager;
	import newx.com.config.StaticIni;
	import newx.com.control.NxClip;
	import newx.com.control.button.NxButton;
	import newx.com.control.comboBox.NxComboBoxEvent;
	import newx.com.control.group.NxViewGroup;
	import newx.com.control.tab.NxTabEvent;
	import newx.com.control.window.NxWindowEvent;
	import newx.com.loader.SwfLoader;

	public class PetLoic
	{
		/** 
		 * 0,
		 * 1,白
		 * 2.绿
		 * 3.蓝
		 * 4.紫红
		 * 5.橙黄
		 * 6.黄
		 * 7.浅黄
		 * 8.灰色
		 */		
		protected const COLOR_TABLE	:Array	=	["#9d9d9d'>","#ffffff'>","#1eff00'>","#20BFF8'>","#a335ee'>","#E8912E'>","#e5cc80'>","#ffff00'>","#9d9d9d'>"];
		private static var _self:PetLoic;
		private var _ui:PetUI;
		private var _model:ModelLocator;
		private var bindFlag:int=-1;
		private var _bindMang:BindManage;
		private var _itemMc:MovieClip;
		private var _img:NxClip;
		/**属性Flag**/
		private var _bingdFlagArr:Array=[];
		/**喂养Flag**/
		private var _bingdFlagArr1:Array=[];
		/**传授Flag**/
		private var _bingdFlagArr2:Array=[];
		/**驯养Flag**/
		private var _bingdFlagArr3:Array=[];
		/**强化Flag**/
		private var _bingdFlagArr4:Array=[];
		private var _clueArr:Array=[];	  //存放宠物线索状态数组	
		/**
		 *当前绑定的宠物对象 
		 */		
		private var _currBindObj:ViewObject; 
		/**
		 *属性界面需要绑定的函数数组 
		 */	
		private var _bindFuncArr:Array=[]; 
		/**
		 *属性界面需要绑定的属性数组
		 */	
		private var _bindPropertyArr:Array=[];
		/**
		 *喂养界面需要绑定的函数数组 
		 */	
		private var _bindFuncArr1:Array=[]; 
		/**
		 *喂养界面需要绑定的属性数组
		 */	
		private var _bindPropertyArr1:Array=[];
		
		/**
		 *传授界面需要绑定的函数数组 
		 */	
		private var _bindFuncArr2:Array=[]; 
		/**
		 *传授界面需要绑定的属性数组
		 */	
		private var _bindPropertyArr2:Array=[];
		
		/**
		 *驯养界面需要绑定的函数数组 
		 */	
		private var _bindFuncArr3:Array=[]; 
		/**
		 *驯养需要绑定的属性数组
		 */	
		private var _bindPropertyArr3:Array=[];
		
		/**
		 *强化界面需要绑定的函数数组 
		 */	
		private var _bindFuncArr4:Array=[]; 
		/**
		 *强化需要绑定的属性数组
		 */	
		private var _bindPropertyArr4:Array=[];
		/**存放线索图品数组**/
		private var _cluepotoArr:Array =[];
		private var _nxclip:NxClip;
		private var _bingNumIndex:int =-1;
		private var _bindFallowIndex:int=-1;
		private var _bindAttackIndex:int=-1;
		private var _bindIndex:int=-1;
		private var _bindVipIndex:int=-1;
		private var _bindLvIndex:int=-1;
		
		private var _culeMC:MovieClip;
		private var _foodArr:Array=[];//喜好食物的数组
		private var _foodMaxNum:int=0;//最大喜好食物数
		/**食物开启个数**/
		private var _openfoodNum:int =1;
		/**
		 *当前选择的食物Pos
		 */		
		private var _currSelectFood:int=0;
//		private var _foodPosArr:Vector.<foodPos>;
		/**
		 存能被传授宠物的容器 
		 */		
		private   var _petArr:Vector.<PetVo>;
		/**
		 *存自己宠物的容器 
		 */		
		private var _setlfPetArr:Array=[];
		private var _groupMc:MovieClip;
		/**喂养消耗数组 0 金币消耗 1 元宝消耗**/
		private var consumeArr:Array=[];  
		/**
		 *当前经验 
		 */		
		private var _currExp:int=0;
		private var _nextExp:int=0;
		/**
		 *当前宠物模型 
		 */		
		private var _actionMovie:MovieClip;
		/**
		 *当前跟随宠物的ID 
		 */		
		private var _currFollowPet:String="";
		/**
		 *当前宠物状态 
		 */	
		private var _currPetState:String="";
		/**
		 *当前战斗宠物
		 */		
		private var _currAttackPet:String="";
		/**
		 *格子状态 1启用状态  2 选中状态 3未启用状态 4未开启滑过
		 */		
		private  const	OPEN_STATE:int  =1,
						OVER_STATE:int  =2,
						CLOSE_STATE:int =3,
						CLOSE_OVER_STATE:int =4;
		
		/**
		 *REMANBER 状态 PET_NO_SECLECT_STATE:1 ,PET_SECLECT_STATE:2
		 */		
		private const PET_NO_SECLECT_STATE:int =1,
						PET_SECLECT_STATE:int=2;
			
		/**经验增加显示的容器**/
		private var showMc:MovieClip;
		private var _showsprite:Sprite;
		/**总喂养次数**/
		private var feedtimes:int;
		
		
				/**翻页**/		
		private var _tableListener			:TurnPapersViewGroup;
				/**所有宠物数组**/
		private var _petVector:Array=[];
		
		/**
		 *最后显示的宠物列表 
		 */		
		private var _petSham:Array=[];
		
		private var _petslectMC:MovieClip;
		private var _equipMC:MovieClip;
		private var _rollUp:MovieClip;
		/**当前战斗宠物在容器中的MC**/
		private var _currFightPetMc:MovieClip;
		/**当前跟随宠物在容器中的MC**/
		private var _currFollwPetMc:MovieClip;
		/**战斗图标**/
		private var _fightmc:MovieClip;
		/**跟随图标**/
		private var _follwmc:MovieClip;
		
		
		private var fightimg:NxClip;
		private var follwimg:NxClip;
		/**精通对象数组**/
		private const propertyArr:Array = [{name:"PetPhyHitProb",cion:"CustomControl_0234",strID:"Pet_Property_07"},{name:"PetPhyDodgeProb",cion:"CustomControl_0235",strID:"Pet_Property_06"},{name:"PetPhyVaProb",cion:"CustomControl_0233",strID:"Pet_Property_12"},
			{name:"PetPhyVaDefProb",cion:"CustomControl_0241",strID:"Pet_Property_13"},{name:"PetPhyWardProb",cion:"CustomControl_0232",strID:"Pet_Property_08"},{name:"PetDePhyWardProb",cion:"CustomControl_0231",strID:"Pet_Property_09"},
			{name:"PetPhyGuardProb",cion:"CustomControl_0238",strID:"Pet_Property_10"},{name:"PetDePhyGuardProb",cion:"CustomControl_0239",strID:"Pet_Property_11"}];
		private const intensifycongfigIDArr:Array=[{ConfigID:"33030001",Property:"PetHPLevel"},{ConfigID:"33030002",Property:"PetPhyDamageLevel"},{ConfigID:"33030003",Property:"PetPhyDefLevel"},{ConfigID:"33030004",Property:"PetMagDamageLevel"},{ConfigID:"33030005",Property:"PetMagDefLevel"}];
		///////////////////////////////////////////////////////////////////

		private var amountIndex:int=-1;
		private var _bindEqueIndex:int =-1;
		private var _petMc:MovieClip;
		private var _img1:NxClip;
		
		private var _petclueMc:MovieClip;
		private var _img2:NxClip;
		
		private var _petequeMc:MovieClip;
		private var _img3:NxClip;

		private var _petgrowthMc:MovieClip;
		private var _img4:NxClip;
		private var _date:Date;
		private var _time:Timer;
		
		private var _currVip:int;
		/**
		 *已经绑定的喜好物 
		 */		
		private var _bindFoodItemArr:Array=[];
		///////////////////////////////////////////////////////////////
		/**
		 *被传授对象 
		 */		
		private var _setdate:Object;
		
		/**完美升级的消耗**/
		private var _gradeConsume:Number=0;
		public static function getInstance():PetLoic
		{
			if(_self==null)
			{
				_self=new PetLoic();
			}
			return _self;
		}
		public function PetLoic()
		{
			
		}
		public function  Init():void
		{
			_fightmc= ResManager.newResClass("CustomControl_0224") as MovieClip
			_follwmc = ResManager.newResClass("CustomControl_0223") as MovieClip
			_date		=	new Date();
			_time=new Timer(1000);
			_petArr=new Vector.<PetVo>();
			_ui = PetUI.getInstance();
			_model	= ModelLocator.getInstance();
			_bindMang	= BindManage.getInstance();
			_tableListener    = new  TurnPapersViewGroup(_ui.petGroup,_ui.preBtn,_ui.nextBtn,showItem,removeItem,afterShowItem,_ui.pageLabel);
			_bindFuncArr		=["name","leve","exp","nextexp","grade","equipBoxIndex","fightPower","growProbability",
								"petMaxHP","petPhyDamage","petPhyDef","petMagDamage","petMagDef",
								"petMaxHPAdd","petPhyDamageAdd","petPhyDefAdd","petMagDamageAdd","petMagDefAdd"];
			
			_bindPropertyArr	=["PetName","Level","Exp","MaxExp","Grade","EquipBoxIndex","FightPower","GrowProbability",
								"PetMaxHP","PetPhyDamage","PetPhyDef","PetMagDamage","PetMagDef",
								"PetMaxHPAdd","PetPhyDamageAdd","PetPhyDefAdd","PetMagDamageAdd","PetMagDefAdd"];
			
			_bindFuncArr1 		=["model1","petName1","level1","exp1","maxExp1","grade","petMaxHP1","petMaxHPNext1",
								"openFavoFoodNum","favofood","maxfoodnum",
								"petPhyDamage1","petPhyDef1","petMagDamage1","petMagDef1",
								"petPhyDamageNext1","petPhyDefNext1","petMagDamageNext1","petMagDefNext1"];
			_bindPropertyArr1 	= ["Model","PetName","Level","Exp","MaxExp","Grade","PetMaxHP","PetMaxHPNext",
								"OpenFavoFoodNum","FavoFood","MaxFavoFoodNum",
								"PetPhyDamage","PetPhyDef","PetMagDamage","PetMagDef",
								"PetPhyDamageNext","PetPhyDefNext","PetMagDamageNext","PetMagDefNext"];
			
			_bindFuncArr2		=["model2","level2","name2","grade"];
			_bindPropertyArr2	=["Model","Level","PetName","Grade"];
			
			_bindFuncArr3		=["model3","petName3","grade",
								"petPhyVaProb3","petPhyVaDefProb3","petDePhyWardProb3","petPhyWardProb3","petPhyHitProb3","petPhyDodgeProb3","petDePhyGuardProb3","petPhyGuardProb3",
								"petPhyVaProbAdd3","petPhyVaDefProbAdd3","petDePhyWardProbAdd3","petPhyWardProbAdd3","petPhyHitProbAdd3","petPhyDodgeProbAdd3","petDePhyGuardProbAdd3","petPhyGuardProbAdd3",
								"petPhyVaProbNext3","petPhyVaDefProbNext3","petDePhyWardProbNext3","petPhyWardProbNext3","petPhyHitProbNext3","petPhyDodgeProbNext3","petDePhyGuardProbNext3","petPhyGuardProbNext3",
								"petPhyVaProbAddNext3","petPhyVaDefProbAddNext3","petDePhyWardProbAddNext3","petPhyWardProbAddNext3","petPhyHitProbAddNext3","petPhyDodgeProbAddNext3","petDePhyGuardProbAddNext3","petPhyGuardProbAddNext3",
								"petMaxHP3","petPhyDamage3","petPhyDef3","petMagDamage3","petMagDef3",
								"petMaxHPAdd3","petPhyDamageAdd3","petPhyDefAdd3","petMagDamageAdd3","petMagDefAdd3",
								"petMaxHPNext3","petPhyDamageNext3","petPhyDefNext3","petMagDamageNext3","petMagDefNext3",
								"petMaxHPAddNext3","petPhyDamageAddNext3","petPhyDefAddNext3","petMagDamageAddNext3","petMagDefAddNext3"];
			_bindPropertyArr3	=["Model","PetName","Grade",
								"PetPhyVaProb","PetPhyVaDefProb","PetDePhyWardProb","PetPhyWardProb","PetPhyHitProb","PetPhyDodgeProb","PetDePhyGuardProb","PetPhyGuardProb",
								"PetPhyVaProbAdd","PetPhyVaDefProbAdd","PetDePhyWardProbAdd","PetPhyWardProbAdd","PetPhyHitProbAdd","PetPhyDodgeProbAdd","PetDePhyGuardProbAdd","PetPhyGuardProbAdd",
								"PetPhyVaProbNextGrade","PetPhyVaDefProbNextGrade","PetDePhyWardProbNextGrade","PetPhyWardProbNextGrade","PetPhyHitProbNextGrade","PetPhyDodgeProbNextGrade","PetDePhyGuardProbNextGrade","PetPhyGuardProbNextGrade",
								"PetPhyVaProbAddNextGrade","PetPhyVaDefProbAddNextGrade","PetDePhyWardProbAddNextGrade","PetPhyWardProbAddNextGrade","PetPhyHitProbAddNextGrade","PetPhyDodgeProbAddNextGrade","PetDePhyGuardProbAddNextGrade","PetPhyGuardProbAddNextGrade",
								"PetMaxHP","PetPhyDamage","PetPhyDef","PetMagDamage","PetMagDef",
								"PetMaxHPAdd","PetPhyDamageAdd","PetPhyDefAdd","PetMagDamageAdd","PetMagDefAdd",
								"PetMaxHPNextGrade","PetPhyDamageNextGrade","PetPhyDefNextGrade","PetMagDamageNextGrade","PetMagDefNextGrade",
								"PetMaxHPAddNextGrade","PetPhyDamageAddNextGrade","PetPhyDefAddNextGrade","PetMagDamageAddNextGrade","PetMagDefAddNextGrade"];
			_bindFuncArr4		=["petHPLevel4","petHPProbability4","petMaxHP4","petMaxHPNext4",
								"petPhyDamageLevel4","petPhyDamageProbability4","petPhyDamage4","petPhyDamageNext4",
								"petPhyDefLevel4","petPhyDefProbability4","petPhyDef4","petPhyDefNext4",
								"petMagDamageLevel4","petMagDamageProbability4","petMagDamage4","petMagDamageNext4",
								"petMagDefLevel4","petMagDefProbability4","petMagDef4","petMagDefNext4"];
			_bindPropertyArr4	=["PetHPLevel","PetHPProbability","PetMaxHP","PetMaxHPNext",
								"PetPhyDamageLevel","PetPhyDamageProbability","PetPhyDamage","PetPhyDamageNext",
								"PetPhyDefLevel","PetPhyDefProbability","PetPhyDef","PetPhyDefNext",
								"PetMagDamageLevel","PetMagDamageProbability","PetMagDamage","PetMagDamageNext",
								"PetMagDefLevel","PetMagDefProbability","PetMagDef","PetMagDefNext"];
			initGroup();
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_ADD_PET_EXP),getExp);
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_FEED_CONSUME),getConsume);
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_PET_LEVEL_UP),petLevelup);
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_PET_COPY_RES_LEVEL),getLevel);
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_REQUEST_FEEDTIMES_INC_TIME),getTimesCD);
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_UPGRADE_PET_GRADE_CONSUME),getgradeConsume);
			_showsprite=new Sprite();
			_ui.addChild(_showsprite);
			initTab();
		}
		/**
		 *初始化丹药控件 添加丹药图片
		 * 
		 */		
		private function initmedbg():void
		{
			var amount:int=0;
			var mc:MovieClip;
			for(var ii:int=0;ii<intensifycongfigIDArr.length;ii++)
			{	 
				var needNum:String= StaticIni.getIniVar("intensifyLv","lv_"+_currBindObj.GetProperties(intensifycongfigIDArr[ii].Property))
				amount = CeckisHaveFood(int(intensifycongfigIDArr[ii].ConfigID));
				mc= _ui.C_viewGroup.getItemByIndex(ii);
				mc["img2"].source =ResManager.newResClass(ResourcesPath.getPropsURL(int(StaticIni.getIniVar(intensifycongfigIDArr[ii].ConfigID,"Photo"))));
				if(amount>=int(needNum))
				{
					(mc["btn"] as SimpleButton).filters =[];
					(mc["btn"] as SimpleButton).enabled=true;
				}
				else
				{
					(mc["btn"] as SimpleButton).enabled=false;
					(mc["btn"] as SimpleButton).filters =[FilterUtil.GrayColorFilter];
				}
				mc["Amount"]=amount;
				
			}
		}
		private function clearmedbg():void
		{
			var amount:int=0;
			var mc:MovieClip;
			for(var ii:int=0;ii<intensifycongfigIDArr.length;ii++)
			{	 
				mc= _ui.C_viewGroup.getItemByIndex(ii);
				mc["img2"].source =null;
			}
		}
		private function BindFunc(PropertiesName:String,PropertiesValue:*,pList:Array):void
		{
			var text:TextField = pList[0];
			var		value:*		=	pList[1];
			text[value]=link_color(String(PropertiesValue),1);	
		}
		private function setshamPet():void
		{
			var mc:MovieClip= _ui.petGroup.getItemByIndex(0);
			mc.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
		}
		/**
		 *读取本地配置本件加载假宠物  
		 * 
		 * @param val  玩家当前等级
		 * 
		 */		
		private function readPetIni(val:int):void
		{
			_petSham=[];
			var petstr:String =StaticIni.getIniVar("pet_num","pet");
			var petIniArr:Array =petstr.split(",");
			for(var i:String in petIniArr)
			{
				if(petIniArr[int(i)])
				{
					var petObj:Object =StaticIni.getIniObj(petIniArr[int(i)]);
					petObj["ConfigID"]=petIniArr[int(i)];
					if(petObj==null)
						continue;
					var needLv:String = petObj["SeeLevel"];
					if(val>=int(needLv))
						_petSham.push(petObj);
				}
			}
			setshamPet();
		}
		/**
		 *当定玩家等级 用于根据等级显示假宠物 
		 * @param val
		 * 
		 */		
		public function set RoleLevel(val:int):void
		{
		}
		private function initTab():void
		{
			_ui.nxtable.clearItems();
			_ui.nxtable.addItem(StaticIni.getSwfLangStr("Pet_Property"));
			_ui.nxtable.addItem(StaticIni.getSwfLangStr("Pet_Feed"));
			_ui.nxtable.addItem(StaticIni.getSwfLangStr("Pet_GradeUp"));
//			_ui.nxtable.addItem(StaticIni.getSwfLangStr("Pet_PowUp"));
			_ui.nxtable.addItem(StaticIni.getSwfLangStr("Pet_Impart"));
		}
		private function initGroup():void
		{
			var len:int=_ui.B_vieGroup.col*_ui.B_vieGroup.row;
			//初始化食物表
			var text:TextField;
			for(var i:int=0;i<len;i++)
			{
				_itemMc=_ui.B_vieGroup.getItemByIndex(i);
				_img=new NxClip();
				_img.x =_itemMc["mg"].x+4;
				_img.y =_itemMc["mg"].y+4;
				_itemMc["mg"].gotoAndStop(OPEN_STATE);
				_itemMc["img"]=_img;
				if(i!=0)
					_itemMc["img"].filters=[FilterUtil.GrayColorFilter];
				_itemMc["index"]=-1;
				_itemMc.addChild(_img);
				text=new TextField();
				text.autoSize=TextFieldAutoSize.LEFT;
				_itemMc.addChild(text);
				_itemMc["text"]=text;
				_itemMc["titleTxt1"].mouseEnabled = _itemMc["titleTxt2"].mouseEnabled=_itemMc["titleTxt3"].mouseEnabled=false;
				_itemMc["titleTxt1"].text = _itemMc["titleTxt2"].text = "";
			}
			//初始化宠物列表
			for(var ii:int=0;ii<_ui.petGroup.col*_ui.petGroup.row;ii++)
			{
				_petMc = _ui.petGroup.getItemByIndex(ii);
				_petMc["titleTxt"].text ="";
				_img1 =new NxClip();
				_img1.x	=	_petMc["p_mc"]["img2"].x+4;
				_img1.y	=	_petMc["p_mc"]["img2"].y+1;
				_img1.source ="";
				_img1.scaleX=_img1.scaleY=0.55;
				_petMc["img"] =_img1;
				_petMc.addChild(_img1);
				
				fightimg =new NxClip();
				fightimg.x =51;
				fightimg.y =34;
				_petMc["frist"] =fightimg;
				fightimg.source ="";
				_petMc.addChild(fightimg);
				
				follwimg =new NxClip();
				follwimg.x =67;
				follwimg.y=34;
				follwimg.source ="";
				_petMc.addChild(follwimg);
				_petMc["second"]=follwimg 
				
			}
			//初始化技能
			for(var iii:int=0;iii<_ui.A_clueGroup.col*_ui.A_clueGroup.row;iii++)
			{
				_petclueMc = _ui.A_clueGroup.getItemByIndex(iii);
				_img2 =new NxClip();
				_img2.source ="";
				_img2.x =_img2.y =0
				_petclueMc["img"] =_img2;
				_petclueMc.addChild(_img2);
			
				(_petclueMc["up"] as MovieClip).visible=false;	
				_petclueMc.gotoAndStop(CLOSE_STATE)
			}
			//初始化装备
			for(var k:int=0;k<_ui.A_equeGroup.col*_ui.A_equeGroup.row;k++)
			{
			 	_petequeMc= _ui.A_equeGroup.getItemByIndex(k);
				_img3 =new NxClip();
				_img3.source ="";
				_img3.x =_img3.y =1
				_petequeMc["img"] =_img3;
				_petequeMc["up"].gotoAndStop(1);
				_petequeMc.addChildAt(_img3,_petequeMc.getChildIndex(_petequeMc["up"]));
				_petequeMc["up"].addEventListener(MouseEvent.ROLL_OVER,function(e:Event):void{
					rollUp=	e.currentTarget as MovieClip
				});
				_petequeMc["up"].addEventListener(MouseEvent.ROLL_OUT,function(e:Event):void{
					rollUp=null;
				});
				(_petequeMc["up"] as MovieClip).visible=false;
				(_petequeMc["up"] as MovieClip).buttonMode=true;
			}
			//初强化
			for(var m:int=0;m<_ui.C_viewGroup.col*_ui.C_viewGroup.row;m++)
			{
				_petgrowthMc= _ui.C_viewGroup.getItemByIndex(m);
				var _img4:NxClip =new NxClip();
				_img4.source ="";
				_img4.x =_img3.y =1
				_petgrowthMc["img"] =_img4;
				_petgrowthMc["txt_1"].text =_petgrowthMc["txt_2"].text =_petgrowthMc["txt_3"].text =_petgrowthMc["txt_5"].text="";
				(_petgrowthMc["txt_4"] as TextField).mouseEnabled=false;
				_petgrowthMc.addChild(_img4);
			}
			showMc	=	new MovieClip();
			showMc.mouseChildren=showMc.mouseEnabled=false;
			_ui.windowBG.addChild(showMc);
		}
		/**
		 *向上箭头  鼠标效果 
		 * @param mc
		 * 
		 */		
		private function set rollUp(mc:MovieClip):void
		{
			if(mc)
			{
				mc.gotoAndStop(2);
			}
			if(_rollUp)
			{
				_rollUp.gotoAndStop(1)
			}
			_rollUp=mc;
		}
		//////////////////////////////////////////////////////////////////////////////////属性//////////////////////////////////////////////////////////////////////////////////
		/**
		 *打开界面 排完序后调用的  重绑第一个 
		 * 
		 */		
		private function bindFristPet():void
		{
			if(_petSham[0] is ViewObject)
			{
				onBindPet(_petSham[0])
			}
			var mc:MovieClip = _ui.petGroup.getItemByIndex(0);
			if(mc && mc["data"] && (mc["data"] is ViewObject))
			{
				onBindPet(mc["data"])
			}
			else if(mc && mc["data"] && (mc["data"] is Object))
			{
				var url:String=	ResPath.ACTORS + "npc_" + String(mc.data.Model) + ".swf";
				loadModel(url,false);
			}
		
		}
		public function set nxTableSelect(val:int):void
		{
			_ui.nxtable.selected = val;
			if(!_ui.created)
			{
				_ui.showOrHide();
			}
		}
		private function onBindPet(obj:ViewObject):void
		{
			if(obj.GetProperties("Impart") == 1) //已经传授
			{
				_ui.nxtable.updataItem(StaticIni.getSwfLangStr("Pet_Impart"),3,null,false);
				if(_ui.nxtable.selected ==3)
					_ui.nxtable.selected=0;
			}
			else
			{
				_ui.nxtable.updataItem(StaticIni.getSwfLangStr("Pet_Impart"),3,null,true);
			}
			if(_ui.nxtable.selected ==0)
			{
				restbind(obj,true);
			}
			else if(_ui.nxtable.selected ==1)
			{
				restbindPropertyUI(obj);
			}
				
		}
		/**
		 *绑定属性界面的接口
		 * @param viewobj
		 * 
		 */		
		public function bySelcetIndexUpdate(viewobj:ViewObject):void
		{
			//是当前选择的宠物 更新
			restbind(viewobj,false);
		}
		/**
		 *重绑属性界面 
		 * @param viewobj
		 * @param acquiesce	是否需要设置默认宠物
		 * 
		 */		
		private function restbind(viewobj:ViewObject,acquiesce:Boolean):void
		{
			if(acquiesce)
			{
				if(viewobj .GetProperties("ConfigID") == _model.scene.Role.GetProperties("FightPet"))
				{
					bindProperty(viewobj);
				}
				else if(viewobj .GetProperties("ConfigID") == _model.scene.Role.GetProperties("FollowPet"))
				{
					bindProperty(viewobj);
				}
				else if( viewobj.ObjKey =="1")
				{
					bindProperty(viewobj);
				}
			}
			else
			{
				bindProperty(viewobj);
			}
			
		}
		/**绑定属性界面宠物**/
		private function  bindProperty(viewobj:ViewObject):void
		{
			deletPropertyBind();
			clearModel();
			//			saveFoodPos(viewobj);
			_currBindObj =viewobj;
			for(var i:int=0;i<_bindFuncArr.length;i++)
			{
				if(viewobj.CheckProperties(_bindPropertyArr[i]))
				{
					_bingdFlagArr[i]=_bindMang.BindProp(viewobj as ObjectData,_bindPropertyArr[i],PetAssistantLogic.getInstance(),_bindFuncArr[i]);
				}
			}
			//现在装备不开放 先注掉 不要删
			//			bindEqueVie();
			setPropertyUI();
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_REQUEST_CONSUME,_currBindObj.GetPropertiesEx("ConfigID"));
			initmedbg();
		}
		//////////////////////////////////////////////////////////////////////////////////喂养////////////////////////////////////////////////////////////////////////////////
		/**
		 * 绑定喂养界面的接口 
		 * @param viewobj
		 * 
		 */		
		public function restbindPropertyUI(vieobj:ViewObject):void
		{
			if(vieobj==null)
				return;
			if(_currBindObj ==null)
			{
				bindPetPropertyUI(vieobj);
			}
			else 
			{
				deletBind();
				//重绑
				bindPetPropertyUI(vieobj);
			}
		}
		/**
		 *绑定喂养界面
		 * 
		 */		
		private function bindPetPropertyUI(vieobj:ViewObject):void
		{
		
			_currBindObj =vieobj;
			for(var i:int=0;i<_bindFuncArr1.length;i++)
			{
				if(vieobj.CheckProperties(_bindPropertyArr1[i]))
				{
					_bingdFlagArr1[i]=_bindMang.BindProp(vieobj as ObjectData,_bindPropertyArr1[i],PetAssistantLogic.getInstance(),_bindFuncArr1[i]);
				}
			}	
//			var obj:Object=StaticIni.getIniObj(_currBindObj.GetProperties("ConfigID"));
//			var str:String = StaticIni.getIniVar(obj["ConfigID"], "Trait");
			_ui.B_text1.htmlText =StaticIni.getSwfLangStr("Pet_Feed_Help");
		}
		/**
		 *解绑喂养界面属性 
		 * 
		 */		
		private function deletBind():void
		{
			if(_currBindObj!=null)
			{
				//解绑
				for(var i:int=0;i<_bindFuncArr1.length;i++)
				{
					if(_currBindObj.CheckProperties(_bindPropertyArr1[i]))
					{
						_bingdFlagArr1[i]=_bindMang.UnbindProp(_currBindObj as ObjectData,_bindPropertyArr1[i],_bingdFlagArr1[i]);
					}
				}
			}
		}
		/////////////////////////////////////////////////////////////////////////传授///////////////////////////////////////////////////////////////////////////////
		/**
		 *绑传授界面接口 
		 * @param vieobj
		 * 
		 */		
		private function restBindImpartUI(vieobj:ViewObject):void
		{
			if(vieobj==null)
				return;
			if(_currBindObj ==null)
			{
				bindPetPropertyUI(vieobj);
			}
			else 
			{
				unImpartbind(vieobj);
				//重绑
				bindImpart(vieobj);
			}
			getInfo();
			_ui.E_infoText.htmlText=StaticIni.getSwfLangStr("Pet_Impart_Des");
		}
		/**
		 *绑定传授界面属性 
		 * 
		 */		
		private function bindImpart(vieobj:ViewObject):void
		{
			_currBindObj =vieobj;
			for(var i:int=0;i<_bindFuncArr2.length;i++)
			{
				if(_currBindObj.CheckProperties(_bindPropertyArr2[i]))
				{
					_bingdFlagArr2[i]=_bindMang.BindProp(vieobj as ObjectData,_bindPropertyArr2[i],PetAssistantLogic.getInstance(),_bindFuncArr2[i]);
				}
			}	
			
			//该宠物能否传授
			var CanImpart:Boolean = _currBindObj.GetProperties("Impart")==1?false:true;
			if(CanImpart)
			{
				_ui.E_impartBtn.enabled=true;
				_ui.E_comboBox.mouseChildren =_ui.mouseEnabled=true;	
			}
			else
			{
				_ui.E_impartBtn.enabled =false;
				_ui.E_comboBox.mouseChildren =_ui.mouseEnabled=false;	
			}
		}
		/**
		 *解绑传授界面属性
		 * 
		 */		
		private function unImpartbind(vieobj:ViewObject):void
		{
			if(_currBindObj!=null)
			{
				//解绑
				for(var i:int=0;i<_bindFuncArr2.length;i++)
				{
					if(_currBindObj.CheckProperties(_bindPropertyArr2[i]))
					{
						_bingdFlagArr2[i]=_bindMang.UnbindProp(_currBindObj as ObjectData,_bindPropertyArr2[i],_bingdFlagArr2[i]);
					}
				}
			}
		}

		////////////////////////////////////////////////////////////////////////驯养//////////////////////////////////////////////////////////////////////////////////////
		/**
		 *绑驯养界面接口 
		 * @param vieobj
		 * 
		 */		
		private function restBindGrowthUI(vieobj:ViewObject):void
		{
			if(vieobj==null)
				return;
			unbindgrowth();
			//重绑
			bindGrowth(vieobj);

		}
		private function bindGrowth(vieobj:ViewObject):void
		{
			_currBindObj =vieobj;
			for(var i:int=0;i<_bindFuncArr3.length;i++)
			{
				if(_currBindObj.CheckProperties(_bindPropertyArr3[i]))
				{
					_bingdFlagArr3[i]=_bindMang.BindProp(vieobj as ObjectData,_bindPropertyArr3[i],PetAssistantLogic.getInstance(),_bindFuncArr3[i]);
				}
			}
			
		}
		private function unbindgrowth():void
		{
			if(_currBindObj!=null)
			{
				//解绑
				for(var i:int=0;i<_bindFuncArr3.length;i++)
				{
					if(_currBindObj.CheckProperties(_bindPropertyArr3[i]))
					{
						_bingdFlagArr3[i]=_bindMang.UnbindProp(_currBindObj as ObjectData,_bindPropertyArr3[i],_bingdFlagArr3[i]);
					}
				}
			}
		}
		////////////////////////////////////////////////////////////////////////////////强化////////////////////////////////////////////////////////////////////////////////////
		/**
		 *绑强化界面接口 
		 * @param vieobj
		 * 
		 */		
		private function restBindintensifyUI(vieobj:ViewObject):void
		{
			if(vieobj==null)
				return;
			unbindintensify();
			//重绑
			bindintensify(vieobj);
		
		}
		private function bindintensify(vieobj:ViewObject):void
		{
			_currBindObj =vieobj;
			for(var i:int=0;i<_bindFuncArr4.length;i++)
			{
				if(_currBindObj.CheckProperties(_bindPropertyArr4[i]))
				{
					_bingdFlagArr4[i]=_bindMang.BindProp(vieobj as ObjectData,_bindPropertyArr4[i],PetAssistantLogic.getInstance(),_bindFuncArr4[i]);
				}
			}
			_ui.C_text.htmlText =StaticIni.getSwfLangStr("Pet_PowUp_Help");
		}
		private function unbindintensify():void
		{
			if(_currBindObj!=null)
			{
				//解绑
				for(var i:int=0;i<_bindFuncArr4.length;i++)
				{
					if(_currBindObj.CheckProperties(_bindPropertyArr4[i]))
					{
						_bingdFlagArr4[i]=_bindMang.UnbindProp(_currBindObj as ObjectData,_bindPropertyArr4[i],_bingdFlagArr4[i]);
					}
				}
			}
		}
		
		////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		public function get currBindPet():ViewObject
		{
			return _currBindObj;
		}
		private function closeUI():void
		{
			tabel1RemoveEvent();
			tabel2RemoveEvent();
			tabel3RemoveEvent();
			tabel4RemoveEvent();
			tabel5RemoveEvent();
			if( bindFlag != -1 )
			{
				bindFlag		=	_bindMang.UnbindView(View.VIEWPORT_TOOL,bindFlag);
			}
		}
		/**
		 *按类型更新界面 
		 * 
		 */		
		private function updaView():void
		{
			PetManageLogic.getInstance().setState(_ui.nxtable.selected)
		}
		private function clearclue():void
		{
			for(var j:int=0;j<_ui.A_clueGroup.row*_ui.A_clueGroup.col;j++)
			{
				var mc:MovieClip =_ui.A_clueGroup.getItemByIndex(j);
				mc["img"].source ="";
			}
		}
		private function rest():void
		{
			if(showMc.numChildren>0)
			{
				showMc.removeChildAt(0);
			}
		}
		private var initfinish:Boolean;
		public function	BeforeShow():void
		{
			if(!SceneManager._itemIconLoad)
			{
				_model.addEventListener(LogicEvent.ITEMICONLOADED,loaded);
				function loaded():void
				{
					BeforeShow();
					_model.removeEventListener(LogicEvent.ITEMICONLOADED,loaded)
				}
			}
			_ui.E_remand1.gotoAndStop(1);
			_ui.E_remand2.gotoAndStop(1);
			_ui.E_remand3.gotoAndStop(1);
			initfinish=false;
			isSavefinish=false;
			initfoodGroup();
			feedtimes = int(StaticIni.getIniVar("pet_feedTimes","times"));
			SystemSender.getInstance().CustomMsg(
				CustomToServerFlag.CLIENT_CUSTOMMSG_REQUEST_FEEDTIMES_INC_TIME);
			SystemSender.getInstance().CustomMsg(
				CustomToServerFlag.CLIENT_CUSTOMMSG_OPEN_PET_UI ,1);
			addEvent();
			updaView();
			bind();
			sort(true);
			initfinish=true;
			_ui.B_uplabel.visible=false;
			_ui.D_btn.label = StaticIni.getSwfLangStr("Pet_Grade_UP_Common");
			_ui.D_upgrade.label = StaticIni.getSwfLangStr("Pet_Grade_UP_Perfect");
			
			//宠物完美升阶消耗(增加宠物ID发送)
			if(PetLoic.getInstance().currBindPet != null)
				SystemSender.getInstance().CustomMsg(
					CustomToServerFlag.CLIENT_CUSTOMMSG_UPGRADE_PET_GRADE_PERFECT_CONSUME,
					PetLoic.getInstance().currBindPet.GetProperties("ConfigID"));
		}
		public function	AfterHide():void
		{
			_ui.nxtable.selected =0;
			closeUI();
			_ui.A_picMc.source =null;
			reset();
			removeEvent();
			unbind();
			if(PetPropertyUI.getInstance().created==false)
					SystemSender.getInstance().CustomMsg(
						CustomToServerFlag.CLIENT_CUSTOMMSG_OPEN_PET_UI ,0);
		}
		/**
		 *界面一监听 
		 * 
		 */		
		public function table1AddEvent():void
		{
			
			if(_currBindObj)
				bySelcetIndexUpdate(_currBindObj);
			_ui.A_changName.addEventListener(MouseEvent.CLICK,onClick);
			_ui.A_remanber.addEventListener(MouseEvent.CLICK,onClick);
			_ui.A_remanber1.addEventListener(MouseEvent.CLICK,onClick);
			
			_ui.B_vieGroup.addItemsEvent(MouseEvent.MOUSE_OVER,onOver);
			_ui.B_vieGroup.addItemsEvent(MouseEvent.MOUSE_OUT,onVieOut);
			_ui.A_attacktarea1.addEventListener(MouseEvent.MOUSE_OVER,onOver);
			_ui.A_attacktarea1.addEventListener(MouseEvent.ROLL_OUT,onVieOut);
			_ui.A_attacktarea2.addEventListener(MouseEvent.MOUSE_OVER,onOver);
			_ui.A_attacktarea2.addEventListener(MouseEvent.ROLL_OUT,onVieOut);
//			_ui.equeGroup.addItemsEvent(MouseEvent.CLICK,onClickEqueGroup);
//			_ui.equeGroup.addItemsEvent(MouseEvent.MOUSE_OVER,onOverEqueGroup);
//			_ui.equeGroup.addItemsEvent(MouseEvent.MOUSE_OUT,onOutEqueGroup);

		}
		/**
		 *移除界面一监听 
		 * 
		 */		
		public function tabel1RemoveEvent():void
		{
		
			_ui.removeEventListener(MouseEvent.CLICK,onClick);
			_ui.A_remanber.removeEventListener(MouseEvent.CLICK,onClick);
			_ui.A_remanber1.removeEventListener(MouseEvent.CLICK,onClick);
			_ui.A_attacktarea1.removeEventListener(MouseEvent.MOUSE_OVER,onOver);
			_ui.A_attacktarea1.removeEventListener(MouseEvent.ROLL_OUT,onVieOut);
			_ui.A_attacktarea2.removeEventListener(MouseEvent.MOUSE_OVER,onOver);
			_ui.A_attacktarea2.removeEventListener(MouseEvent.ROLL_OUT,onVieOut);
//			_ui.equeGroup.removeItemsEvent(MouseEvent.CLICK,onClickEqueGroup);
//			_ui.equeGroup.removeItemsEvent(MouseEvent.MOUSE_OVER,onOverEqueGroup);
//			_ui.equeGroup.removeItemsEvent(MouseEvent.MOUSE_OUT,onOutEqueGroup);
		
		}
		/**
		 *界面二监听 
		 * 
		 */		
		public function table2AddEvent():void
		{
			if(_bingNumIndex == -1)
			{
				_bingNumIndex =_bindMang.BindProp(_model.scene.Role,"FeedTimes",this,"feedNum");
			}
			if(_currBindObj)
				restbindPropertyUI(_currBindObj);
			if( bindFlag == -1 )
			{
				bindFlag		=	_bindMang.BindView(_model.scene,View.VIEWPORT_TOOL,OnAddPack,OnRemovePack,null,updatafunc);
				
			}
			_ui.B_vieGroup.addItemsEvent(MouseEvent.CLICK,onVieClick);
			_ui.B_vieGroup.addItemsEvent(MouseEvent.MOUSE_OUT,onVieOut);
			_ui.B_vieGroup.addItemsEvent(MouseEvent.MOUSE_OVER,onVieOver);
			_ui.B_timelabel.addEventListener(MouseEvent.MOUSE_OVER,onOver);
			_ui.B_timelabel.addEventListener(MouseEvent.MOUSE_OUT,onVieOut);
			_ui.B_numLabel.addEventListener(MouseEvent.MOUSE_OVER,onOver);
			_ui.B_numLabel.addEventListener(MouseEvent.MOUSE_OUT,onVieOut);
		}
		/**
		 *移除界面二监听 
		 * 
		 */		
		public function tabel2RemoveEvent():void
		{
			if(_bingNumIndex != -1)
			{
				_bingNumIndex =_bindMang.UnbindProp(_model.scene.Role,"FeedTimes",_bingNumIndex);
			}
			if( bindFlag != -1 )
			{
				bindFlag		=	_bindMang.UnbindView(View.VIEWPORT_TOOL,bindFlag);
			}
			_ui.B_vieGroup.removeItemsEvent(MouseEvent.CLICK,onVieClick);
			_ui.B_vieGroup.removeItemsEvent(MouseEvent.MOUSE_OVER,onVieOver);
			_ui.B_vieGroup.removeItemsEvent(MouseEvent.MOUSE_OUT,onVieOut);
			_ui.B_timelabel.removeEventListener(MouseEvent.MOUSE_OVER,onOver);
			_ui.B_timelabel.removeEventListener(MouseEvent.MOUSE_OUT,onVieOut);
			_ui.B_numLabel.removeEventListener(MouseEvent.MOUSE_OVER,onOver);
			_ui.B_numLabel.removeEventListener(MouseEvent.MOUSE_OUT,onVieOut);
		}
		/**
		 *界面三监听 
		 * 
		 */		
		public function table3AddEvent():void
		{
			if(_bindVipIndex ==-1)
			{
				_bindVipIndex =_bindMang.BindProp(_model.scene.Role,"VIPLevel",this,"vip");
			}
			if(_currBindObj)
				restBindImpartUI(_currBindObj);
			_ui.E_impartBtn.addEventListener(MouseEvent.CLICK,onClickImpart);
			_ui.E_comboBox.addEventListener(NxComboBoxEvent.NXCOMBOBOX_CLICK,onClickBox);
			_ui.E_remand1.addEventListener(MouseEvent.CLICK,onClick);
			_ui.E_remand2.addEventListener(MouseEvent.CLICK,onClick);
			_ui.E_remand3.addEventListener(MouseEvent.CLICK,onClick);
		}
		/**
		 *移除界面三监听 
		 * 
		 */		
		public function tabel3RemoveEvent():void
		{
			if(_bindVipIndex !=-1)
			{
				_bindVipIndex =_bindMang.UnbindProp(_model.scene.Role,"VIPLevel",_bindVipIndex);
			}
			_ui.E_impartBtn.removeEventListener(MouseEvent.CLICK,onClickImpart);
			_ui.E_comboBox.removeEventListener(NxComboBoxEvent.NXCOMBOBOX_CLICK,onClickBox);
			_ui.E_remand1.removeEventListener(MouseEvent.CLICK,onClick);
			_ui.E_remand2.removeEventListener(MouseEvent.CLICK,onClick);
			_ui.E_remand3.removeEventListener(MouseEvent.CLICK,onClick);
		}
		/**
		 *界面四监听 
		 * 
		 */		
		public function table4AddEvent():void
		{
			if( bindFlag == -1 )
			{
				bindFlag		=	_bindMang.BindView(_model.scene,View.VIEWPORT_TOOL,OnAddPack,OnRemovePack,null,updatafunc);
				
			}
			if(_currBindObj)
				restBindintensifyUI(_currBindObj)
			_ui.C_viewGroup.addItemsEvent(MouseEvent.CLICK,onClickmedBtn);
		}
		/**
		 *移除界面四监听 
		 * 
		 */		
		public function tabel4RemoveEvent():void
		{
			if( bindFlag != -1 )
			{
				bindFlag		=	_bindMang.UnbindView(View.VIEWPORT_TOOL,bindFlag);
			}
			_ui.C_viewGroup.removeItemsEvent(MouseEvent.CLICK,onClickmedBtn);
		}
		/**
		 *界面五监听 
		 * 
		 */		
		public function table5AddEvent():void
		{
			if( bindFlag == -1 )
			{
				bindFlag		=	_bindMang.BindView(_model.scene,View.VIEWPORT_TOOL,OnAddPack,OnRemovePack,null,updatafunc);
			}
			if(_currBindObj)
				restBindGrowthUI(_currBindObj)
			_ui.D_btn.addEventListener(MouseEvent.CLICK,onClick);
			_ui.D_btn.addEventListener(MouseEvent.MOUSE_OVER,onOver);
			_ui.D_btn.addEventListener(MouseEvent.MOUSE_OUT,onVieOut);
			
			_ui.D_Item.addEventListener(MouseEvent.MOUSE_OVER,onOver);
			_ui.D_Item.addEventListener(MouseEvent.MOUSE_OUT,onVieOut);
			_ui.D_ItemLable2.addLinkClickHandel(onback);
			
			_ui.D_upgrade.addEventListener(MouseEvent.CLICK,onClick);
			_ui.D_upgrade.addEventListener(MouseEvent.MOUSE_OVER,onOver);
			_ui.D_upgrade.addEventListener(MouseEvent.MOUSE_OUT,onVieOut);
		}
		/**
		 *移除界面五监听 
		 * 
		 */		
		public function tabel5RemoveEvent():void
		{
			if( bindFlag != -1 )
			{
				bindFlag		=	_bindMang.UnbindView(View.VIEWPORT_TOOL,bindFlag);
			}
			_ui.D_btn.removeEventListener(MouseEvent.CLICK,onClick);
			_ui.D_btn.removeEventListener(MouseEvent.MOUSE_OVER,onOver);
			_ui.D_btn.removeEventListener(MouseEvent.MOUSE_OUT,onVieOut);
			
			_ui.D_Item.removeEventListener(MouseEvent.MOUSE_OVER,onOver);
			_ui.D_Item.removeEventListener(MouseEvent.MOUSE_OUT,onVieOut);
			_ui.D_ItemLable2.removeLinkClickHandel();
			
			_ui.D_upgrade.removeEventListener(MouseEvent.CLICK,onClick);
			_ui.D_upgrade.removeEventListener(MouseEvent.MOUSE_OVER,onOver);
			_ui.D_upgrade.removeEventListener(MouseEvent.MOUSE_OUT,onVieOut);
		}
		private function onback(name:String):void
		{
			UIManage.getInstance().requestOpenUI(ForbiddenZoneUI.getInstance());
		}
		private function addEvent():void
		{
			
			_tableListener.addListener();
			_ui.windowBG.addEventListener(NxWindowEvent.WINDOW_CLOSE,onClose);
			_ui.petGroup.addItemsEvent(MouseEvent.CLICK,onClickTable);
			_ui.nxtable.addEventListener(NxTabEvent.TAB_CLICK,onClickTab);
			_time.addEventListener(TimerEvent.TIMER,playTime);
			_ui.helpLable.addEventListener(MouseEvent.MOUSE_OVER,onOverHandle);
			_ui.helpLable.addEventListener(MouseEvent.MOUSE_OUT,onOutHandle);
		}
		private function removeEvent():void
		{
			_tableListener.removeListener();
			_ui.windowBG.removeEventListener(NxWindowEvent.WINDOW_CLOSE,onClose);
			_ui.petGroup.removeItemsEvent(MouseEvent.CLICK,onClickTable);
			_ui.nxtable.removeEventListener(NxTabEvent.TAB_CLICK,onClickTab);
			_time.removeEventListener(TimerEvent.TIMER,playTime);
			_ui.helpLable.removeEventListener(MouseEvent.MOUSE_OVER,onOverHandle);
			_ui.helpLable.removeEventListener(MouseEvent.MOUSE_OUT,onOutHandle);
		}
		private function onOverHandle(e:MouseEvent):void
		{
			TipsMainLogic.instance.showWideString(StaticIni.getSwfLangStr("Pet_Help_1"));
		}
		private function onOutHandle(e:MouseEvent):void
		{
			TipsMainLogic.instance.hide();
		}
		/**
		 *点击文本超链接 
		 * @param val
		 * 
		 */		
		private function onClickText(val:String):void
		{
			var eplist:Array=val.split(",");
			if(eplist.length==0)return;
			var currLv:int= _model.scene.Role.getPlayerLevel();
			if(eplist[0] == "clue_1")
			{
				var npcid:String =StaticIni.getIniVar("clue_1","npcid");
				var npcmodel:BasePlayerModel=SceneManager.getInstance().norSceneView.scenePlayerLogic.getScenePlayByConfigID(npcid);
				if(npcmodel!=null)
				{
					SceneManager.getInstance()._sceneClickLogic.sceneClick(GameData.Role as BasePlayerModel,npcmodel)
				}
				else
				{
					NoticeUI.getInstance().showInfo(StaticIni.getSwfLangStr("UIString_1000471"));//无扫荡目标
				}
			}
			else if(eplist[0] == "clue_2")
			{
				if(!FriendUI.getInstance().created)
					FriendUI.getInstance().showOrHide();
			}
		}
		private function bind():void
		{
		
			if(_bindLvIndex ==-1)
			{
				_bindLvIndex =_bindMang.BindProp(_model.scene.Role,"Level",this,"RoleLevel");
			}
			if(_bindIndex== -1)
			{
				_bindIndex = _bindMang.BindView(_model.scene,View.VIRWPORT_PET,onAddPet,removePet,null,updateFunc);
				isSavefinish=true;
			}
			if(_bindFallowIndex ==-1)
			{
				_bindFallowIndex =_bindMang.BindProp(_model.scene.Role,"FollowPet",this,"followPet");
			}
			if(_bindAttackIndex ==-1)
			{
				_bindAttackIndex =_bindMang.BindProp(_model.scene.Role,"FightPet",this,"attackPet");
			}
			
		}
		private function unbind():void
		{
			if(_bindIndex != -1)
			{
				_bindIndex = _bindMang.UnbindView(View.VIRWPORT_PET,_bindIndex);
				isSavefinish=false;
			}
			if(_bindLvIndex !=-1)
			{
				_bindLvIndex =_bindMang.UnbindProp(_model.scene.Role,"Level",_bindLvIndex);
			}
			if(_bindFallowIndex !=-1)
			{
				_bindFallowIndex =_bindMang.UnbindProp(_model.scene.Role,"FollowPet",_bindFallowIndex);
			}
			if(_bindAttackIndex !=-1)
			{
				_bindAttackIndex =_bindMang.UnbindProp(_model.scene.Role,"FightPet",_bindAttackIndex);
			}
		}
		/**
		 *宠物升级 
		 * @param e
		 * 
		 */		
		private function petLevelup(e:CustomMsgEvent):void
		{
			new PointPlayLite(_showsprite, new Point(_ui.A_expMc.x,_ui.A_expMc.y), McPool.borrowRes( "upgrade" ) );
		}

		/**
		 * 获取宠物增加经验 
		 * @param e
		 * 
		 */		
		private function getExp(e:CustomMsgEvent=null):void
		{
			var congfigid:int=e.pList[0];
			if(congfigid !=_currBindObj.GetProperties("ConfigID"))
			{
				return;
			}
			var exp:int = e.pList[2];
			var state:int = e.pList[3];
			var type:int;
			if(state ==0)  //喂养
			{
				exp =-exp;
				type=1;
			}
			else
			{
				type=2;
				play();
			}
			ShowDamageNum.ShowDamageEffect(exp,new Point(_ui.B_loadingLab.x+60,_ui.B_loadingLab.y+100),showMc,type);
		}
		/**
		 *获取当前宠物喂养的消耗  consumeArr[0]金币喂养的消耗  consumeArr[1]元宝喂养的消耗
		 * @param e
		 * 
		 */		
		private function getConsume(e:CustomMsgEvent):void
		{
			consumeArr=[e.pList[0],e.pList[1]];
			
		}
		/**
		 *喂养次数 
		 * @param val
		 * 
		 */		
		public function set feedNum(val:int):void
		{
			var surplus:int =feedtimes;
			surplus=surplus>=0?surplus:0;
			if(surplus==val)
			{
				_ui.B_timelabel.visible=false;
			}
			else
			{
				_ui.B_timelabel.visible=true;
			}
			_ui.B_numLabel.htmlText=StaticIni.getSwfLangStrVar("UIString_1000398",[val,feedtimes]);
		}
		private function initfoodGroup():void
		{
			var mc:MovieClip;
			for(var i:int=0;i<_ui.B_vieGroup.col*_ui.B_vieGroup.row;i++)
			{
				mc = _ui.B_vieGroup.getItemByIndex(int(i));
				var num:int = CeckisHaveFood(mc["date"]);
				if(int(i)==0)
						continue;
				(mc["img"] as NxClip).filters=[FilterUtil.GrayColorFilter];
			}
		}
		/**
		 *重置界面 
		 * 
		 */		
		private function reset():void
		{
//			_foodPosArr=new Vector.<foodPos>();
			unbind();
			deletBind()
			deletPropertyBind();
			clearModel();
//			_currBindObj=null;
			rest();
			clearclue();
			clearmedbg();
			_ui.D_Item.source =null;
		}

		/**
		 *更新被能被传授宠物数组 
		 * @param PropertiesValue
		 * 
		 */		
		private function updatebeimpartArr(PropertiesValue:ViewObject):void
		{
			var beimpart:int =PropertiesValue.GetProperties("BeImpart"); //被传授次数 0能  1 不能传授
			var configid:int=PropertiesValue.GetProperties("ConfigID");
			
			if(	_setdate&&int(_setdate.configid) ==configid)
			{
				_setdate.grade =PropertiesValue.GetProperties("Grade");
				_setdate.level=PropertiesValue.GetProperties("Level");
				_setdate.beimpart = beimpart;
				updateBeimpart(_setdate);
				if(beimpart ==1)
				{
					_ui.E_mc8.gotoAndPlay(1);
					_ui.E_mc8.addFrameScript(_ui.E_mc8.totalFrames-1,function():void
					{
						_ui.E_mc8.gotoAndStop(1);
						_ui.E_mc8.addFrameScript(_ui.E_mc8.totalFrames-1,null);
					});
				}
			}		
			if(beimpart!=1)
			{
				var model:int=PropertiesValue.GetProperties("Model");
				var name:String=PropertiesValue.GetProperties("PetName");
				var level:int =PropertiesValue.GetProperties("Level");
				var impart:int =PropertiesValue.GetProperties("Impart");
				var grade:int = PropertiesValue.GetProperties("Grade")
				for(var i:String in _petArr)
				{
					if(int(_petArr[int(i)].configid) ==configid)
					{
						_petArr[int(i)].name =name;
						_petArr[int(i)].level =level;
						_petArr[int(i)].impart =impart;
						_petArr[int(i)].beimpart =beimpart;
						_petArr[int(i)].grade =grade;
						return ;
					}
					
				}
				_petArr.push(new PetVo(String(configid),model,name,level,impart,beimpart,grade));
			}
			else
			{
				for(var ii:String in _petArr)
				{
					if(int(_petArr[int(ii)].configid) ==configid)
					{
						_petArr.splice(int(ii),1);
						return;
					}
					
				}
			}
		}
		private function updateFunc(PropertiesName:String,PropertiesValue:ViewObject,data:*):void
		{
			savePet(PropertiesValue,false);
			
		}
		/**
		 *保存自己得到的宠物 
		 * @param obj
		 * 
		 */		
		private function saveSelfPet(obj:ViewObject):void
		{
			for(var i:int=0; i< _setlfPetArr.length;i++)
			{
				if(_setlfPetArr[i].GetProperties("ConfigID") ==obj.GetProperties("ConfigID"))
				{
					_setlfPetArr[i] = obj;
					return;
				}
			}
			_setlfPetArr.push(obj);
		}
		protected function link_color(str:String,color:int):String
		{
			if( color >8)
			{
				color	=	1;
			}
			return ("<font color ='"+COLOR_TABLE[color]+str+"</font>");
		}
		private function onAddPet(PropertiesName:String,PropertiesValue:ViewObject,data:*):void
		{
//			initfinish=true;
			savePet(PropertiesValue,true);
//			setIndexUpdate(PropertiesValue);
//			saveFoodPos(PropertiesValue);
		}
		/**
		 * 显示对象
		 * @param	mc
		 * @param	data
		 */
		public function showItem(mc:MovieClip,PropertiesValue:*):void 
		{
//			updatepet(mc,data)
			var model:int;
			var color:int;
			var name:String;
			var index :int = _ui.petGroup.getChildIndex(mc);
			
			if(PropertiesValue is ViewObject)
			{
				color =PropertiesValue.GetProperties("Grade");
				if(PropertiesValue.GetProperties("ConfigID") ==21000701)
				{
					color =color-1;
				}
				model =PropertiesValue.GetProperties("Model");
				name  =PropertiesValue.GetPropertiesEx("PetName")
				PropertiesValue.HandleProperties("mc",mc);
				saveSelfPet(PropertiesValue);
				mc["data"] =PropertiesValue;
				if(_model.scene.Role.GetProperties("FightPet") == PropertiesValue.GetProperties("ConfigID"))
				{
					currFightPetMc(mc,true);
				}
				else
				{
					currFightPetMc(mc,false);
				}
				if(_model.scene.Role.GetProperties("FollowPet") == PropertiesValue.GetProperties("ConfigID"))
				{
					currFollwPetMc(mc,true)
				}
				else
				{
					currFollwPetMc(mc,false);
				}
			}
			else
			{
				color =0;
				model =49330100;
				name = "???"
				mc["data"] =PropertiesValue;
				currFightPetMc(mc,false);
				currFollwPetMc(mc,false);
				PropertiesValue["mc"]=mc;
			}
			
			(mc["img"] as NxClip).source =ResourcesPath.getHeadPic(model);
			(mc["titleTxt"] as TextField).htmlText=link_color( name,color);
			
		}
		/**
		 * 删除对象
		 * @param	mc
		 */
		public function removeItem(mc:MovieClip):void 
		{
			mc["img"].source ="";
			mc["titleTxt"].text = "";
			mc["data"] =null
		}
		/**
		 * 翻页后的操作
		 */
		public function afterShowItem():void
		{
		
			if(_petslectMC)
			{	
				_petslectMC.gotoAndStop(OPEN_STATE);
			}
		}
		/**
		 *根据ID在宠物视图中超找宠物
		 * @param configid 
		 * @return  找到返回改宠物  找不到返回NULL
		 * 
		 */		
		public function byCoinIDCkeckPet(configid:int):ViewObject
		{
			var petVo:View		=	_model.scene.GetView(View.VIRWPORT_PET);
			if(!petVo)return null;
			for (var property:String in petVo.Properties) 
			{
				if(int(property))
				{
					if(petVo.CheckProperties(property))
					{
						var item:ViewObject=petVo.GetPropertiesEx(property);
						if(item.GetPropertiesEx("ConfigID")==configid)
						{
							return item;
						}
					}
				}
				
			}
			return null;
		}

		/**
		 *宠物列表排序调用的函数   优先级： 出战--- 跟随--- 自己的  
		 * @param isRestBind  是否需要重新绑定为第一个宠物
		 */		
		private function sort(isRestBind:Boolean=false):void
		{
			_petSham=PetAssistantLogic.getInstance().sort(_petSham);
			_tableListener.dataProvider =_petSham;
			if(isRestBind)
				bindFristPet();
		}
		
		private var isSavefinish:Boolean;
		/**
		 *保存所有的宠物
		 * @param petObj
		 * @param isBindFristPet 是否需要绑定默认的宠物
		 * @param isSort 
		 * 
		 */		
		private function savePet(petObj:ViewObject,isBindFristPet:Boolean,isSort:Boolean=true):void
		{
			if(petObj==null)
				return;
			updatebeimpartArr(petObj);	
			var index:int=returnHave(petObj.GetProperties("ConfigID"));
			//没有该假宠物添加到后面
			if(index ==-1)
			{
				_petSham.push(petObj);
			}
			else
			{
				_petSham[index]=petObj;
			}
			if(initfinish)
			{
				sort(isBindFristPet);
			}
			function returnHave(configid:int):int
			{
				for(var i:int=0;i<_petSham.length;i++)
				{
					if(_petSham[i] is ViewObject)
					{
						if((_petSham[i] as ViewObject).GetProperties("ConfigID")==configid)
							return i;
					}
					else
					{
						if(_petSham[i]["ConfigID"] == configid)
						{
							return i;
						}
					}
				}
				return -1;
				
			}
		}
		/**
		 *删除宠物属性界面绑定 
		 * 
		 */		
		private function deletPropertyBind():void
		{
			if(_currBindObj!=null)
			{
				//解绑属性
				for(var i:int=0;i<_bindFuncArr.length;i++)
				{
					if(_currBindObj.CheckProperties(_bindPropertyArr[i]))
					{
						_bingdFlagArr[i]=_bindMang.UnbindProp(_currBindObj as ObjectData,_bindPropertyArr[i],_bingdFlagArr[i]);
					}
				}
				//解绑装备视图 装备没开放 先不注掉不要删
//				unbindEqueVie();
			}
		}
	
//		private function saveFoodPos(viewobj:ViewObject):void
//		{
//			var isHave:Boolean=false;
//			for(var ii:String in _foodPosArr)
//			{
//				if(_foodPosArr[int(ii)].configid == viewobj.GetProperties("ConfigID"))
//				{
////					_foodPosArr[int(ii)].pos =0;
//					isHave=true;
//				}
//			}
//			if(!isHave)
//				_foodPosArr.push(new foodPos(viewobj.GetProperties("ConfigID"),0));
//		}

		/**
		 *绑定装备视图 
		 * 
		 */		
		private function bindEqueVie():void
		{
			var recd:Record= _model.scene.GetRecordEx("PetViewIDRec");
			if(recd==null)
				return
			for(var i:String in recd.recArr)
			{
				if(_currBindObj.GetPropertiesEx("ConfigID") ==recd.recArr[int(i)][0])
				{
					var vieID:int =recd.recArr[int(i)][1];
					_currBindObj.HandleProperties("ViewID",vieID);
					if(_bindEqueIndex ==-1)
					{
						_bindEqueIndex =_bindMang.BindView(_model.scene,vieID,addEqueFun,onRemoveItem);
					}
					return;
				}
			}
		}
		/**
		 *解绑装备视图 
		 * 
		 */		
		private function unbindEqueVie():void
		{
			var recd:Record= _model.scene.GetRecordEx("PetViewIDRec");
			if(recd==null)
				return
			for(var i:String in recd.recArr)
			{
				if(_currBindObj.GetPropertiesEx("ConfigID") ==recd.recArr[int(i)][0])
				{
					var vieID:int =recd.recArr[int(i)][1];
					if(_bindEqueIndex !=-1)
					{
						_bindEqueIndex =_bindMang.UnbindView(vieID,_bindEqueIndex);
					}
					for(var ii:int =0; ii< _ui.A_equeGroup.col*_ui.A_equeGroup.row;ii++)
					{
						var mc:MovieClip = _ui.A_equeGroup.getItemByIndex(ii);
						(mc["up"] as MovieClip).visible=false;
						mc["img"].source ="";
						mc["data"]=null;
					}
					return;
				}
			}
		}
		/**
		 *添加宠物装备 
		 * @param propertiesName
		 * @param propertiesValue
		 * @param data
		 * 
		 */		
		private function addEqueFun(propertiesName:String,propertiesValue:ViewObject,data:*):void
		{
			var mc:MovieClip =_ui.A_equeGroup.getItemByIndex(int(propertiesValue.ObjKey)-1);
			mc["img"].source = ResourcesPath.getPropsURL(propertiesValue.GetProperties("Photo"));
			mc["data"] =propertiesValue;
			(mc["up"] as MovieClip).visible=true;
			(mc["up"] as MovieClip).mouseChildren=(mc["up"] as MovieClip).mouseEnabled=true
		}
		/**
		 * 删除宠物装备
		 */
		private function onRemoveItem(propertiesName:String,propertiesValue:*,data:*):void
		{
			var mc:MovieClip =_ui.A_equeGroup.getItemByIndex(int(propertiesValue.ObjKey)-1);
			mc["img"].source = "";
			mc["data"] =null;
			(mc["up"] as MovieClip).visible=false;
		}
		private var _isLoadMode:Boolean=false;
		private var _lastUrl:String="";
		private var _lastBool:Boolean;
		private function loadModel(url:String,isRealMode:Boolean):void
		{
			if(!_isLoadMode)
			{
				_isLoadMode=true;
				SwfLoader.StartLoad( url, null, onLoadResComplete ,[isRealMode]);
			}
			else
			{
				_lastUrl=url;
				_lastBool=isRealMode;
			}
			function onLoadResComplete(movic:MovieClip,pList:Array):void
			{	
				if(pList[0])
				{
					_currPetState =PetAssistantLogic.Wait
				}
				else
				{
					_currPetState =PetAssistantLogic.NormalWait
				}
				
				_actionMovie=movic;
				_ui.A_picMc.source =movic;
				if(_currPetState !="")
				{
					playMc(_currPetState);
				}
				_isLoadMode=false;
				if(_lastUrl&&(_lastUrl!=url||pList[0]!=_lastBool))
				{
					loadModel(_lastUrl,_lastBool)
					_lastUrl="";
				}
				else
				{
					_lastUrl="";
				}
			}
		}
		/**存放精通类型**/
		private const masteryPicVecotr:Array =["","","",""];
		/**
		 *设置精通 
		 * 
		 */		
		private function setMastery():void
		{
			var index:int=1;
			var value:int=0;
			var mc:MovieClip;
			for(i in propertyArr)
			{
				if(_ui["A_masterycoin"+(int(i)+1)])
				{
					if((_ui["A_masterycoin"+(int(i)+1)] as NxClip).hasEventListener(MouseEvent.MOUSE_OVER))
					{
						(_ui["A_masterycoin"+index] as NxClip).removeEventListener(MouseEvent.MOUSE_OVER,onOver);
						(_ui["A_masterycoin"+index] as NxClip).removeEventListener(MouseEvent.MOUSE_OUT,onVieOut);
					}
					(_ui["A_masterycoin"+(int(i)+1)] as NxClip).source=null;
				}
					
			}
			for(var i:String in propertyArr)
			{
				if(index<=8)
				{
					value = _currBindObj.GetProperties(propertyArr[i].name);
					if(value ==0)
						continue;
					if(_ui["A_masterycoin"+index])
					{
						(_ui["A_masterycoin"+index] as NxClip).source =propertyArr[i].cion; 
					}
					else
					{
						_ui["A_masterycoin"+index]=new NxClip;
						_ui.windowBG.addChild(_ui["A_masterycoin"+index]);
						(_ui["A_masterycoin"+index] as NxClip).source =propertyArr[i].cion; 
						(_ui["A_masterycoin"+index] as NxClip).y = (_ui["A_masterycoin"+(index-1)] as NxClip).y;
						(_ui["A_masterycoin"+index] as NxClip).x = (_ui["A_masterycoin"+(index-1)] as NxClip).x+17
					}
					(_ui["A_masterycoin"+index] as NxClip).addEventListener(MouseEvent.MOUSE_OVER,onOver);
					(_ui["A_masterycoin"+index] as NxClip).addEventListener(MouseEvent.MOUSE_OUT,onVieOut);
					index++;
				}
			}
		}
		private function setPropertyUI():void
		{
			setModel();
			setMastery();
			updateFollowPet();
			updateAttackPet();
			_ui.A_labbel20.htmlText= StaticIni.getSwfLangStr(StaticIni.getIniVar(_currBindObj.GetProperties("ConfigID"),"Trait"));
			_ui.A_prolvLab.htmlText= StaticIni.getSwfLangStr("Pet_ActOn");
			_ui.A_masteryLable.htmlText= StaticIni.getSwfLangStr("Pet_Versed");
		}
		/**
		 *设置模型 
		 * 
		 */		
		public function setModel():void
		{
			var url:String=	ResPath.ACTORS + "npc_" + String(_currBindObj.GetProperties("Model")) + ".swf";
			loadModel(url,true)
		}
		/**
		 *删除模型 
		 * 
		 */		
		private function clearModel():void
		{
			_actionMovie=null;
			if(_ui.A_picMc.source !=null)
			{
				_ui.A_picMc.source="";
			}
		}
		/**	未启用待机*/
		private function petNormalWait():void
		{
			playMc( PetAssistantLogic.NormalWait );
		}
		/**	启用待机*/
		private function petWait():void
		{
			playMc( PetAssistantLogic.Wait );
		}
		/**	高兴开始*/
		private function petDelight():void
		{
			playMc( PetAssistantLogic.Delight );
		}
		private function playMc( frameName : String ):void
		{
			_currPetState=frameName;
			try
			{
				_actionMovie.gotoAndPlay( frameName );
			}catch(e:Error){};
		}
		/**
		 *更新按钮状态 
		 * 
		 */		
		private function undatePetState():void
		{

			_ui.A_remanber.enabled=true;
//			_ui.btn1.enabled=_ui.btn2.enabled=_ui.btn3.enabled=_ui.btn4.enabled=true;
			_ui.A_remanber.mouseEnabled=true;
//			_ui.A_btn1.mouseEnabled=_ui.btn2.mouseEnabled=_ui.btn3.mouseEnabled=_ui.btn4.mouseEnabled=true;
//			_ui.infolabel.visible=true;
			_ui.A_nameLabel.htmlText = _currBindObj.GetPropertiesEx("PetName");
//			if(_currBindObj.GetProperties("Impart") ==1)
//				_ui.btn1.enabled =false;
//			else
//				_ui.btn1.enabled = true;
			petWait();

		}
		public function removePet(PropertiesName:String,PropertiesValue:ViewObject,data:*):void
		{
			
		}
		public function updateShowExp():void
		{
			switch(_ui.nxtable.selected)
			{
				case 0:
					_ui.A_expMc.htmlText =_currExp+"/"+_nextExp;
					_ui.A_expLoading.bar =(_currExp/_nextExp)*100;
					break;
				case 1:
					_ui.B_loadingLab.htmlText=_currExp+"/"+_nextExp;
					_ui.B_proloading.bar =(_currExp/_nextExp)*100;
					break;
			}
			
		}
		/**
		 *更新当前选中宠物跟随状态 
		 * 
		 */		
		public function updateFollowPet():void
		{
			if(_currBindObj !=null)
			{
				if(_currBindObj.GetPropertiesEx("ConfigID")==_currFollowPet)
				{
					_ui.A_remanber.gotoAndStop(PET_SECLECT_STATE);
					
					return ;
				}
			}
			try
			{
				_ui.A_remanber.gotoAndStop(PET_NO_SECLECT_STATE);
			}catch(e:Error){};
			
			
		}
		private function currFightPetMc(val:MovieClip,isshow:Boolean):void
		{
			if(val ==null)
			{
				if(_currFightPetMc)
					(_currFightPetMc["second"] as NxClip).source=""
						return;
			}
			if(isshow)
			{
				if(_currFightPetMc)
					_currFightPetMc["frist"].source="";
				 (val["frist"] as NxClip).source= _fightmc;
				 _currFightPetMc =val;
			}
			else
			{
				if(_currFightPetMc)
					(val["frist"] as NxClip).source=""
			}
		}
		private function  currFollwPetMc(val:MovieClip,ishow:Boolean):void
		{	
			if(val ==null)
			{
				if(_currFollwPetMc)
					(_currFollwPetMc["second"] as NxClip).source="";
				return;
			}
			if(ishow)
			{
				if(_currFollwPetMc)
					(_currFollwPetMc["second"] as NxClip).source=""
				val["second"].source=_follwmc;
				_currFollwPetMc =val;
			}
			else
			{
				if(_currFollwPetMc)
					(val["second"] as NxClip).source=""
			}
		}
		/**
		 *更新当前选中战斗宠物状态 
		 * 
		 */		
		public function updateAttackPet():void
		{
			if(_currBindObj !=null)
			{
				if(_currBindObj.GetPropertiesEx("ConfigID")==_currAttackPet)
				{
					_ui.A_remanber1.gotoAndStop(PET_SECLECT_STATE);
					return ;
				}
			}
			try
			{
				_ui.A_remanber1.gotoAndStop(PET_NO_SECLECT_STATE);
			}catch(e:Error){};
			
			
		}
		/**VIP**/
		public function set vip(val:int):void
		{
//			var needLv:String=StaticIni.getIniVar("PetUI_Need","openLv");
			_currVip = val;
			if(_ui.nxtable.selected == 3)
				PetAssistantLogic.getInstance().seImpartUI(impartInfo);
		}

		/**战斗的宠物**/
		public function set attackPet(val:int):void
		{
			_currAttackPet =String(val);
			updateAttackPet();
//			sort();
			if(val==0)
			{
				if(_currFightPetMc)
					currFightPetMc(_currFightPetMc,false)
			}
			else
			{
				currFightPetMc(petMC(val),true);
			}
		}
		/**
		 *查找宠物在显示列表中的MC 
		 * @param congfigid
		 * @return 
		 * 
		 */		
		private function  petMC(congfigid:int):MovieClip
		{
			var mc:MovieClip;
			for(var i:int=0;i<_setlfPetArr.length;i++)
			{
				if(_setlfPetArr[i].GetProperties("ConfigID") == congfigid &&_setlfPetArr[i].CheckProperties("mc"))
				{
					mc= _setlfPetArr[i].GetProperties("mc");
					if(mc.data is ViewObject &&mc.data.GetProperties("ConfigID") == congfigid)
					{
						return mc;

					}
				}
			}
			return null;
		}
	
		/**跟随的宠物**/
		public function set followPet(val:int):void
		{
			_currFollowPet =String(val);	
			updateFollowPet();
//			sort();
			if(val==0)
			{
				if(_currFollwPetMc)
					currFollwPetMc(_currFollwPetMc,false);
			}
			else
			{
				currFollwPetMc(petMC(val),true);
			}
		}

		private function animation(movie:MovieClip,index:int):void
		{
			movie.addFrameScript(index,function():void
			{
				movie.stop();
//				_ui.upgradeMC.visible=false;
			} );
//			_ui.upgradeMC.visible=true;
			movie.gotoAndPlay(1);
		}

		private function parse(val:int):String
		{
			var culeStr:String = val.toString(2);
			var len:int=5-culeStr.length;
			var zeroStr5:String = "00000";
			var nZeroStr:String = zeroStr5.substr(0, len);
			return nZeroStr+culeStr;
		}

		/**
		 *检查当前绑定宠物是否自己的宠物 
		 * 
		 */		
		private function checkIsSelf():Boolean
		{
			var isSelf:Boolean=true;
			for(var i:String in _clueArr)
			{
				if(_clueArr[int(i)]==0)
				{
					isSelf=false;
					break;
				}
			}
			return isSelf;
		}
		/**
		 * 检查当前绑定宠物能否查看宠物属性 和模型 
		 * @return 
		 * 
		 */		
		private function checkCanLook():Boolean
		{
			var isSelf:Boolean=false;
			for(var i:String in _clueArr)
			{
				if(_clueArr[int(i)]==1)
				{
					 return isSelf=true;
				}
			}
			return false;
		}
		public function get currPetisSelf():Boolean
		{
			var isSelf:Boolean=checkIsSelf()
			return isSelf;
		}
//		/**
//		 *获取当前宠物选择喜好食物位置 
//		 * @return 
//		 * 
//		 */		
//		private function updatefoodSelectstate():int
//		{
//			for(var i:String in _foodPosArr)
//			{
//				if(_currBindObj.GetProperties("ConfigID")==_foodPosArr[int(i)].configid)
//				{
//					return _foodPosArr[int(i)].pos;
//				}
//			}
//			return -1;
//		}
//		/**
//		 *更新喜好物格子开启状态 
//		 * @param lv
//		 * 
//		 */		
//		public function updatafoodOpen(lv:int):void
//		{
//			var len:int=_ui.B_vieGroup.col*_ui.B_vieGroup.row;
//			var sourIndex:int=updatefoodSelectstate();
//			for(var i:int=0;i<len;i++)
//			{
//				_itemMc=_ui.B_vieGroup.getItemByIndex(i);
//				if(i+1<=lv)
//				{
//					(i==sourIndex)?_itemMc.gotoAndStop(OVER_STATE):_itemMc.gotoAndStop(OPEN_STATE);
//				}
//				else
//				{
//					_itemMc.gotoAndStop(CLOSE_STATE);
//				}
//			}
//		}
	
//		/**
//		 *更新喜好食物
//		 * 
//		 */		
//		public function updateFood():void
//		{
//			var len:int=_ui.B_vieGroup.col*_ui.B_vieGroup.row;
//			var sourIndex:int=updatefoodSelectstate();
//			for(var i:int=0;i<len;i++)
//			{
//				_itemMc=_ui.B_vieGroup.getItemByIndex(i);
//				if(i>=_foodMaxNum)
//				{
//					_itemMc.visible=false;
//				}
//				else
//				{
//					_itemMc.visible=true;
//					if(i>=_openfoodNum) //未打开
//					{
//						_itemMc.gotoAndStop(CLOSE_STATE);
//					}
//					else
//					{
//						if(_foodArr[i]!=null)
//						{
//							(i==sourIndex)?_itemMc.gotoAndStop(OVER_STATE):_itemMc.gotoAndStop(OPEN_STATE);
//						}
//					}
//				}
//			}
//		}
		/**
		 *检查背包中物品的数量 
		 * @param ConfigId
		 * @param type 默认是1返回数量  2返回第一个找到的物品
		 * @return 
		 * 
		 */		
		public function CeckisHaveFood(ConfigId:int,type:int=1):*
		{
			var packVo:View		=	_model.scene.GetView(View.VIEWPORT_TOOL);
			//背包数量
			var packCount:int=0;
			if(packVo !=null)
			{
				for (var property:String in packVo.Properties) 
				{
					if(int(property))
					{
						if(packVo.CheckProperties(property))
						{
							var item:ViewObject=packVo.GetPropertiesEx(property);
							if(item.GetPropertiesEx("ConfigID")==ConfigId)
							{
								if(type ==2)
								{
									return item;
								}
								if(item.CheckProperties("Amount"))
								{
									packCount+=item.GetPropertiesEx("Amount");
								}
								else
								{
									packCount++;
								}
							}
						}
					}
				}
			}
			if(type == 2)
				return null;
			return packCount;
		}
		private function onClickTable(e:MouseEvent):void
		{
			var mc:MovieClip = e.currentTarget as MovieClip;
		
			if(mc!=null &&mc.data!=null)
			{
				if(_petslectMC)
				{
					_petslectMC.gotoAndStop(OPEN_STATE);
				}
				mc.gotoAndStop(OVER_STATE);
				_petslectMC =mc;
				if((mc.data as ViewObject).GetProperties("Impart") == 1) //已经传授
				{
					_ui.nxtable.updataItem(StaticIni.getSwfLangStr("Pet_Impart"),3,null,false);
					if(_ui.nxtable.selected ==3)
						_ui.nxtable.selected=0;
				}
				else
				{
					_ui.nxtable.updataItem(StaticIni.getSwfLangStr("Pet_Impart"),3,null,true);
				}
				if((mc.data is ViewObject) &&_currBindObj !=mc.data)
				{		
					switch(_ui.nxtable.selected)
					{
						case 0:
							bySelcetIndexUpdate(mc.data);
							break;
						case 1:
							restbindPropertyUI(mc.data);
							break;
						case 2:
							restBindGrowthUI(mc.data);
							break;
//						case 3:
//							restBindintensifyUI(mc.data);
//							break;
						case 3:
							restBindImpartUI(mc.data);
							break;
					}
				}
//				else
//				{
//					if(_ui.nxtable.selected ==1 || _ui.nxtable.selected ==2)
//					{
//						_ui.nxtable.selected =0;
//					}
//					deletPropertyBind();
//					_currBindObj=null;
//					updateShamPet();
//					updaView();
//					 var url:String=	ResPath.ACTORS + "npc_" + String(mc.data.Model) + ".swf";
//					 loadModel(url,false);
//				}
			}
		}
		private function updateShamPet():void
		{
			if(_currBindObj ==null)
			{
//				setUISatate(false)
				initUI(_ui.A_equeGroup);
				initUI(_ui.A_clueGroup);
				initUI(_ui.B_vieGroup);
			}
		}
		private function setUISatate(val:Boolean):void
		{
//			if(val)
//			{
//				_ui.A_changName.enabled =true;
////				_ui.btn4.enabled=true;
//				_ui.nxtable.updataItem("属性",1,null,true);
//				_ui.nxtable.updataItem("传授",2,null,true);
//			}
//			else
//			{
//				_ui.gradeMC.gotoAndStop(1);
//				_ui.remanber.gotoAndStop(1);
//				_ui.remanber1.gotoAndStop(1);
//				_ui.nxtable.updataItem("属性",1,null,false);
//				_ui.nxtable.updataItem("传授",2,null,false);
//				_ui.A_expMc.text="";
//				_ui.bellipotent.text="";
//				_ui.A_expLoading.bar=0;
//				_ui.A_changName.enabled =false;
//				_ui.nameLabel.color =0xffffff;
//				_ui.nameLabel.text =_ui.lvLabel.text="???";
////				_ui.btn4.enabled=false;
//			}
		}
		private function initUI(group:NxViewGroup):void
		{
			for(var i:int =0; i< group.col*group.row;i++)
			{
			  	var mc:MovieClip = group.getItemByIndex(i);
			  
				mc["img"].source ="";
				mc.gotoAndStop(CLOSE_STATE);
				mc["data"]=mc["date"]=null;
			}
		}
		private function onClose(e:NxWindowEvent):void
		{
			_ui.hide();
		}
//		private function callfunc():void
//		{
//			//元宝喂养
//			if(_currBindObj!=null)
//				SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_FEED_PET,_currBindObj.GetPropertiesEx("ConfigID"),3);
//		}
//		/**
//		 *获取当前喂养食物的id 
//		 * @return 
//		 * 
//		 */		
//		private function getCurrFoodID():int
//		{
//			var index:int = updatefoodSelectstate();
//			var mc:MovieClip = _ui.B_vieGroup.getItemByIndex(index);
//			if(mc!=null)
//				return  mc["date"];
//			return _foodArr[0];
//		}
		private function onClick(e:MouseEvent):void
		{
			switch(e.target)
			{
				case _ui.A_changName:
					if(_currBindObj)
						AlertUI.showAlert(StaticIni.getSwfLangStr("Pet_ReName"),"",AlertUI.OK|AlertUI.CANCEL,onChangeNameBack,null,true);
					break;
				case _ui.A_picMc:
					if(_currBindObj)
					{
						_ui.nxtable.selected=1;
						TipsMainLogic.instance.hide();
					}
						
					break;
				case _ui.D_btn:  //训练
					SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_PET_UP_GRADE,_currBindObj.GetPropertiesEx("ConfigID"),0);
					break;
				case _ui.D_upgrade:
					SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_PET_UP_GRADE,_currBindObj.GetPropertiesEx("ConfigID"),1);
					break;
				case _ui.E_remand1:
					if(_ui.E_remand1.currentFrame == 1)
					{
						_ui.E_remand1.gotoAndStop(2);
					}
					else
					{
						_ui.E_remand1.gotoAndStop(1);
					}
					break;
				case _ui.E_remand2:
					if(_ui.E_remand2.currentFrame == 1)
					{
						_ui.E_remand2.gotoAndStop(2);
						_ui.E_remand3.gotoAndStop(1);
					}
					else
					{
						_ui.E_remand2.gotoAndStop(1);
						_ui.E_remand3.gotoAndStop(1);
					}
					break;
				case _ui.E_remand3:
					if(_ui.E_remand3.currentFrame == 1)
					{
						_ui.E_remand3.gotoAndStop(2);
						_ui.E_remand2.gotoAndStop(1);
					}
					else
					{
						_ui.E_remand3.gotoAndStop(1);
						_ui.E_remand2.gotoAndStop(1);
					}
					break;
				case _ui.A_remanber:    //跟随状态
					sendFollowChangMsg();
					break;
				case _ui.A_remanber1:   //战斗状态
					sendFightChangMsg();
					break;
			}
		}
		/**
		 *打开禁地商店 回调
		 * 
		 */		
		private function opensellBack():void
		{
			UIManage.getInstance().requestOpenUI(ForbiddenZoneUI.getInstance());
		}
	
//		/**
//		 *点击用元宝购买饲料 
//		 * @param type
//		 * @param str
//		 * @param clickData
//		 * 
//		 */		
//		private function clickCallBack(type:int, str:String, clickData:*):void
//		{
//			if(AlertUI.YES == type)
//			{
//				SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_FEED_PET,_currBindObj.GetPropertiesEx("ConfigID"),3,clickData[0]);
//			}
//		}
		/**
		 *改名 
		 * @param type
		 * @param str
		 * @param clickData
		 * 
		 */		
		private function onChangeNameBack(type:int, str:String, clickData:*):void
		{
			if(AlertUI.OK == type)
			{
				SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_CHANGE_NAME,int(_currBindObj.GetProperties("ConfigID")),new WString(str));
			}
		}
//		/**
//		 *检查该宠物能否传授 
//		 * 
//		 */		
//		private function checkCanimpart():Boolean
//		{
//			//该宠物能否传授
//			var Can:Boolean = _currBindObj.GetPropertiesEx("Impart")==1?false:true;
//			if(Can==false)
//			{
//				NoticeUI.getInstance().showInfo(StaticIni.getSwfLangStr("该宠物不能传授"));//无扫荡目标
//			}
//			return Can;
//		}
		/**
		 *请求更改跟随状态 
		 * 
		 */		
		private function sendFollowChangMsg():void
		{
			if(_currBindObj==null) return;
			if(_ui.A_remanber.currentFrame ==PET_NO_SECLECT_STATE)
			{
				SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_SET_PET_FOLLOW,_currBindObj.GetPropertiesEx("ConfigID"),1);
			}
			else if(_ui.A_remanber.currentFrame == PET_SECLECT_STATE)
			{
				SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_SET_PET_FOLLOW,_currBindObj.GetPropertiesEx("ConfigID"),0);
			}
		}
		/**
		 *请求更改战斗状态 
		 * 
		 */		
		private function sendFightChangMsg():void
		{
			if(_currBindObj==null) return;
			if(_ui.A_remanber1.currentFrame ==PET_NO_SECLECT_STATE)
			{
				SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_SET_FIGHT_PET,_currBindObj.GetPropertiesEx("ConfigID"),1);
			}
			else if(_ui.A_remanber1.currentFrame == PET_SECLECT_STATE)
			{
				SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_SET_FIGHT_PET,_currBindObj.GetPropertiesEx("ConfigID"),0);
			}
		}
		public function get petArr():Vector.<PetVo>
		{
			return _petArr;
		}
		private function onClickTab(e:NxTabEvent):void
		{
			updaView();
		}
		private function onVieClick(e:MouseEvent):void
		{
			if(_currBindObj ==null)return;
			var mc:MovieClip = e.currentTarget as MovieClip;
			var index:int=_ui.B_vieGroup.getChildIndex(mc);
			var configid:int;
			if(mc && mc["date"]&& e.target==mc["btn"])
			{
				configid =int(mc.date);
				if(configid ==48001069 ) //选中的喂养是铜钱
				{
					SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_FEED_PET,_currBindObj.GetPropertiesEx("ConfigID"),1);
				}
				else
				{
					if(_currBindObj.GetProperties(configid.toString())=="0")
					{
						SitAlerLogic.getIntatic().setUIinfo("Pet_No_Food",[StaticIni.getIniVar(configid,"MagicCoinReplace")],
							 function clickBlackfun():void
							{		
								SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_FEED_PET,_currBindObj.GetPropertiesEx("ConfigID"),3,configid);
							},mc,true,true,opensellBack,StaticIni.getSwfLangStr("Pet_ForbidArea_Shop"));
						
				
					}
					else
					{
						SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_FEED_PET,_currBindObj.GetPropertiesEx("ConfigID"),2,configid);
					}
				}
			}
		}
		private function onVieOver(e:MouseEvent):void
		{
			var mc:MovieClip =e.currentTarget as MovieClip;
			if(mc==null ||(mc!=null &&mc["date"]==null)||mc.currentFrame==CLOSE_STATE)return;
			if(_ui.B_vieGroup.getChildIndex(mc)==0)
			{
				var str:String = StaticIni.getSwfLangStrVar("Pet_Feed_Coin",[consumeArr[0]]);
				TipsMainLogic.instance.showString(str);
			}
			else
			{
				if(e.target == mc["btn"])
				{
					
				}
				else
				{
					var obj:Object=TipsMainLogic.instance.getStaticObjWithID(mc["date"]);
				}
			
				TipsMainLogic.instance.showMain(obj);
			}
		}
		private function onVieOut(e:MouseEvent):void
		{
			TipsMainLogic.instance.hide();
		}
		private function play():void
		{
			_ui.B_uplabel.visible=true;
			var mcX:Number =_ui.B_prolvMc.x+50;
			var mcY:Number =_ui.B_prolvMc.y;
			_ui.B_uplabel.x = mcX;
			_ui.B_uplabel.y = mcY;
			_ui.B_uplabel.htmlText = StaticIni.getSwfLangStr("Pet_Feed_Happy");
			var targetPoint:Point =new Point(mcX,mcY-100);
			TweenLite.to(_ui.B_uplabel,distance()/60,{x:targetPoint.x,y:targetPoint.y,onComplete:complete});
			 function distance():Number
			 {
				 return Point.distance(new Point(_ui.B_uplabel.x,_ui.B_uplabel.y),targetPoint);
			 }
		}
		private  function complete():void
		{
			_ui.B_uplabel.visible=false;
		}
		private function onOver(e:MouseEvent):void
		{
			var strID:String="";
			switch(e.target)
			{
				case _ui.A_picMc:
					if(_currBindObj ==null)
						return;
					var obj:Object=StaticIni.getIniObj(_currBindObj.GetProperties("ConfigID"));
					if(obj !=null)
					{
						strID=obj["description"];
					}
					break;	
				case _ui.B_numLabel:
				case _ui.B_timelabel:
					strID="Pet_Feed_Back";
					break;
				case _ui.A_attacktarea1:
					strID = "Pet_ActOnPVP";
					break;
				case _ui.A_attacktarea2:
					strID = "Pet_ActOnForbidArea";
					break;
				case _ui.D_Item:
					if(_ui.D_Item.data)
					{
						var configid:int =_ui.D_Item.data.GetProperties("ConfigID");
						TipsMainLogic.instance.showMain(configid);
					}
					return;
				default:
				{
					var mc:* = e.currentTarget 
					if(mc&&mc.parent is NxViewGroup )
					{
						
					}
					else if(mc is NxClip)
					{
						strID="";
						for each(var i:* in propertyArr)
						{
							if(mc.source == i.cion)
							{
								strID=StaticIni.getSwfLangStrVar(i.strID,[_currBindObj.GetProperties(i.name)]);
							}
						}
					}
					else if(mc  is NxButton)
					{
						if(_ui.D_upgrade.contains(mc))
						{
							var showstr:String = StaticIni.getSwfLangStrVar("Pet_Grade_UP_Perfect_Tips",[_gradeConsume]);
							TipsMainLogic.instance.showString(showstr);
							return;
						}
						else if(_ui.D_btn.contains(mc))
						{
							strID ="Pet_Grade_UP_Common_Tips"
						}
					}
				}
			}
			var str:String=StaticIni.getSwfLangStr(strID);
			TipsMainLogic.instance.showString(str);
		}
		private function onClickEqueGroup(e:MouseEvent):void
		{
			if(_currBindObj==null)return;
			var mc:MovieClip =e.currentTarget as MovieClip;
			if(mc&&mc["data"])
			{
				if( mc["up"].contains(e.target as DisplayObject))
				{
					var viewID:int = currPetView
					var obj:ViewObject = mc["data"] as ViewObject;
					ComposeItemLogic.getInstance().UpgradeItem =obj
					ComposeItemLogic.getInstance().SetItem(obj,2,viewID,0);
				}
				else
				{
					MenuListManager.clickItem(PetLoic,mc["data"]);
				}
			}
			else if(mc.currentFrame == CLOSE_STATE || mc.currentFrame ==CLOSE_OVER_STATE)
			{//请求开启装备格子
				SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_OPEN_EQUIP_INDEX,_currBindObj.GetProperties("ConfigID"));
			}
		}
		private function onOverEqueGroup(e:MouseEvent):void
		{
			if(_equipMC)
			{
				if(_equipMC.currentFrame == OVER_STATE)
				{
					_equipMC.gotoAndStop(OPEN_STATE);
				}
				else if(_equipMC.currentFrame == OVER_STATE)
				{
					_equipMC.gotoAndStop(CLOSE_STATE);
				}
			}
			
			var mc:MovieClip =e.currentTarget as MovieClip;
			if(mc)
			{
				if(mc.currentFrame == OPEN_STATE)
				{
					mc.gotoAndStop(OVER_STATE);
				}
				else if(mc.currentFrame == CLOSE_STATE)
				{
					mc.gotoAndStop(CLOSE_OVER_STATE);
				}
				_equipMC =mc;
			}
			if(mc&&mc["data"])
			{
				TipsMainLogic.instance.showMain(mc["data"]);
			}
		}
		private function onOutEqueGroup(e:MouseEvent):void
		{
			if(_equipMC)
			{
				if(_equipMC.currentFrame == OVER_STATE)
				{
					_equipMC.gotoAndStop(OPEN_STATE);
				}
				else if(_equipMC.currentFrame == OVER_STATE)
				{
					_equipMC.gotoAndStop(CLOSE_STATE);
				}
				_equipMC =null;
			}
			var mc:MovieClip =e.currentTarget as MovieClip;
			if(mc)
			{
				if(mc.currentFrame == OVER_STATE)
				{
					mc.gotoAndStop(OPEN_STATE);
				}
				else if(mc.currentFrame == CLOSE_OVER_STATE)
				{
					mc.gotoAndStop(CLOSE_STATE);
				}
			}
			TipsMainLogic.instance.hide();
		}
		/**
		 *获取当前宠物的装备视图 
		 * @return 
		 * 
		 */		
		public function get currPetView():int
		{
			if(_currBindObj)
			{
				if(_currBindObj.CheckProperties("ViewID"))
				{
					return _currBindObj.GetProperties("ViewID");	
				}
			}
			return -1;
		}
		/**
		 *根据ID查找该宠物的视图ID 
		 * @param configID
		 * @return 
		 * 
		 */		
		public function byCoinfigidFindViewID(configID:int):int
		{
			var recd:Record= _model.scene.GetRecordEx("PetViewIDRec");
			if(recd==null)
				return -1;
			for(var i:String in recd.recArr)
			{
				if(configID ==recd.recArr[int(i)][0])
				{
					var vieID:int =recd.recArr[int(i)][1];
					return vieID;
				}
			}
			return -1;
		}
		/**
		 *获取增加喂养次数的CD 
		 * @param e
		 * 
		 */		
		private function getTimesCD(e:CustomMsgEvent):void
		{
			_date.time =e.pList[0]*1000;
			if(_date.time>0)
				_time.start();
		}
		private function getgradeConsume(e:CustomMsgEvent):void
		{
			_gradeConsume = e.pList[0];
		}
		private var currTimer:int=0;
		private function playTime(e:TimerEvent):void
		{
			if(_date.time>=1000)
			{
				currTimer++;
				_date.time-=1000;
				var str:String=MysterySellLogic.getInstance().getTimeStr(_date);
				_ui.B_timelabel.htmlText=str;
				if(currTimer>=30)
				{
					currTimer=0;
					SystemSender.getInstance().CustomMsg(
						CustomToServerFlag.CLIENT_CUSTOMMSG_REQUEST_FEEDTIMES_INC_TIME);
				}
				if(_date.time <= 0)
				{
					SystemSender.getInstance().CustomMsg(
						CustomToServerFlag.CLIENT_CUSTOMMSG_REQUEST_FEEDTIMES_INC_TIME);
					_time.reset();
				}
			}
			else
			{
				SystemSender.getInstance().CustomMsg(
					CustomToServerFlag.CLIENT_CUSTOMMSG_REQUEST_FEEDTIMES_INC_TIME);
				_time.reset();
				_ui.B_timelabel.htmlText="00:00:00";
			}
		}
		/**
		 *开启的喜好物个数 
		 * @param val
		 * 
		 */		
		public function set openfoodNum(val:int):void
		{
			_openfoodNum =val
		}
		public function set foodMaxNum(val:int):void
		{
			_foodMaxNum =val;
		}
		public function set currExp(val:int):void
		{
			_currExp =val;
		}
		public function set nextExp(val:int):void
		{
			_nextExp =val;
		}
		private function clearFoodGroup():void
		{
			for(var i:int=0;i<_ui.B_vieGroup.col* _ui.B_vieGroup.row;i++)
			{
				_itemMc=_ui.B_vieGroup.getItemByIndex(i);
				(_itemMc["img"] as NxClip).source=null;
				_itemMc["index"]=-1;
				_itemMc["data"]=null;
		
			}
		}
		private function OnAddPack(PropertiesName:String,PropertiesValue:ViewObject,data:*):void
		{
			if(_currBindObj ==null) return;
			updatefeed(PropertiesValue);
			updateIntensify(PropertiesValue);
			PetAssistantLogic.getInstance().updateBtnState();
		}
		private function updatafunc(PropertiesName:String,PropertiesValue:ViewObject,data:*):void
		{
			if(_currBindObj ==null) return;
			updateIntensify(PropertiesValue)
		}
		/**更新强化界面**/
		private function updateIntensify(PropertiesValue:ViewObject):void
		{
			var amount:int=0;
			var mc:MovieClip;
			for(var ii:int=0;ii<intensifycongfigIDArr.length;ii++)
			{	 
				if(int(intensifycongfigIDArr[ii].ConfigID) == PropertiesValue.GetProperties("ConfigID"))
				{
					var needNum:String= StaticIni.getIniVar("intensifyLv","lv_"+_currBindObj.GetProperties(intensifycongfigIDArr[ii].Property))
					amount = CeckisHaveFood(int(intensifycongfigIDArr[ii].ConfigID));
					mc= _ui.C_viewGroup.getItemByIndex(ii);
					if(amount>=int(needNum))
					{
						(mc["btn"] as SimpleButton).filters =[];
						(mc["btn"] as SimpleButton).enabled=true;
					}
					else
					{
						(mc["btn"] as SimpleButton).enabled=false;
						(mc["btn"] as SimpleButton).filters =[FilterUtil.GrayColorFilter];
					}
					mc["Amount"]=amount;
				}
			}
		}
		/**更新喂养**/
		private function updatefeed(PropertiesValue:ViewObject):void
		{
			var mc:MovieClip;
			var model:int;
			for(var i:int=0; i<_foodArr.length;i++)
			{
				if(_foodArr[i]["ConfigID"] == PropertiesValue.GetProperties("ConfigID"))
				{
					mc = _ui.B_vieGroup.getItemByIndex(int(_foodArr[i]["index"]));
					if(!mc)
						continue;
					mc["img"].filters=null;
					model = int(StaticIni.getIniVar(_foodArr[i]["ConfigID"],"Photo"));
					(mc["img"] as NxClip).source =ResourcesPath.getPropsURL(model);
					_currBindObj.HandleProperties(PropertiesValue.GetProperties("ConfigID"),PropertiesValue.GetProperties("Amount"));
				}
			}
		}
		private function OnRemovePack(PropertiesName:String,PropertiesValue:ViewObject,data:*):void
		{
			if(_currBindObj ==null) return;
			var mc:MovieClip;
			var model:int;
			var Amount:int;
			for(var i:int=0; i<_foodArr.length;i++)
			{
				if(int(_foodArr[i]["ConfigID"]) == PropertiesValue.GetProperties("ConfigID"))
				{
					mc = _ui.B_vieGroup.getItemByIndex(int(_foodArr[i]["index"]));
					if(!mc)
						return;
					Amount = CeckisHaveFood(int(_foodArr[i]["ConfigID"]))
					if(Amount==0)
					{
						_currBindObj.HandleProperties(PropertiesValue.GetProperties("ConfigID"),Amount);
					}
					mc["img"].filters=Amount==0?[FilterUtil.GrayColorFilter]:null;
				}
			}
			updateIntensify(PropertiesValue);
			PetAssistantLogic.getInstance().updateBtnState();
		}
		public function set foodArr(arr:Array):void
		{
			_foodArr =arr
			clearFoodGroup();
			var mc:MovieClip;
			var model:int;
			var amount:int;
			for(var i:int=0; i<_ui.B_vieGroup.col*_ui.B_vieGroup.row;i++)
			{	
				mc = _ui.B_vieGroup.getItemByIndex(i);
				var addExp:String ;
				var addVaProb:String;
				if(i>0)
				{
					if(i>_foodArr.length-1)return;
					model = int(StaticIni.getIniVar(int(_foodArr[i]["ConfigID"]),"Photo"));
					amount = CeckisHaveFood(int(_foodArr[i]["ConfigID"]));
					_currBindObj.HandleProperties(String(_foodArr[i]["ConfigID"]),amount);
					addExp =StaticIni.getIniVar(_foodArr[i]["ConfigID"],"PetExp");
					addVaProb =StaticIni.getIniVar(_foodArr[i]["ConfigID"],"VaProb");
				}
				else
				{
					model = int(_foodArr[i]["ConfigID"]);
					addExp =String(200);
					addVaProb=String(1);
				}
				mc["titleTxt1"].htmlText = StaticIni.getSwfLangStrVar("Pet_Feed_Exp",[addExp]);
				mc["titleTxt2"].htmlText = StaticIni.getSwfLangStrVar("Pet_Feed_Happy_Per",[addVaProb]);
				mc["date"]=int(_foodArr[i]["ConfigID"]);
				var Amount:int = CeckisHaveFood(int(_foodArr[i]["ConfigID"]))
				_currBindObj.HandleProperties(_foodArr[i]["ConfigID"],Amount);
				(mc["img"] as NxClip).source =ResourcesPath.getPropsURL(model);
			}
			
		}
		////////////////////////////////////////////////////////////////////////////////喂养界面//////////////////////////////////////////////////////////////////////////////////
		/**
		 *点击吃丹药 
		 * @param e
		 * 
		 */		
		private function onClickmedBtn(e:MouseEvent):void
		{
			var mc:MovieClip = e.currentTarget as MovieClip;
			if(mc)
			{
				var index:int= _ui.C_viewGroup.getChildIndex(mc);
				SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_PET_UPGRADE,_currBindObj.GetProperties("ConfigID"),index+1);
			}
		
		}
		/**
		 *用元宝购买丹药 
		 * @param type
		 * @param str
		 * @param clickData
		 * 
		 */		
		private function clickBack(type:int, str:String, clickData:*):void
		{
			if(AlertUI.YES == type)
			{
				sendeatItem(clickData[0]);
			}
		}
		/**
		 * 请求吃丹药 
		 * @param index  要的类型 
		 * 
		 */		
		private function sendeatItem(index:int):void
		{
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_USE_PET_MEDICAL,_currBindObj.GetProperties("ConfigID"),index);
		}	
		////////////////////////////////////////////////////////////////////////传授//////////////////////////////////////////////////////////////////
		private function onClickImpart(e:MouseEvent):void
		{
			if(_setdate !=null)
			{
				SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_PET_COPY_EXP,_currBindObj.GetProperties("ConfigID"),int(_setdate.configid),
					_ui.E_remand1.currentFrame,_ui.E_remand2.currentFrame,_ui.E_remand3.currentFrame);
//				_ui.impartBtn.enabled=false;
			}
		}
		/**
		 *更新传授容器信息 
		 * @param e
		 * 
		 */		
		public function getInfo():void
		{
			var _petVec1:Vector.<PetVo>=new Vector.<PetVo>();;
			_petVec1 =_petArr;
			var _petArr1:Array=[];
			for(var i:String in _petVec1 )
			{
				if(_petVec1[int(i)].configid ==_currBindObj.GetProperties("ConfigID") ||_petVec1[int(i)].beimpart == 1)
					continue;
				if(_petVec1[int(i)].configid == "21000701")
				{
					_petArr1.push({label:link_color(_petVec1[int(i)].name,int(_petVec1[int(i)].grade -1)),date:_petVec1[int(i)]});
				}
				else
				{
					_petArr1.push({label:link_color(_petVec1[int(i)].name,_petVec1[int(i)].grade),date:_petVec1[int(i)]});
				}
			}
			if(_petArr1.length>0)
			{
				_ui.E_comboBox.dataProvider=_petArr1;
				updateBeimpart(_petArr1[0].date);
				_setdate =_petArr1[0].date;
				send();
			}
			else
			{
				_ui.E_impartBtn.enabled=false;
				_ui.E_star2.visible=false;
				_ui.E_comboBox.dataProvider=[];
				_ui.E_comboBox.clear();
				_ui.E_rlvLab.htmlText ="";
				_ui.E_picMC2.source="";
				_setdate=null;
			}
			
		}
		private var impartInfo:Array=[];
		/**
		 *获取传授后的宠物等级 
		 * @param e
		 * 
		 */		
		private function getLevel(e:CustomMsgEvent):void
		{
			var afterLv:int =0;
			afterLv =	e.pList[1];
			_ui.E_rlvLab.htmlText =_setdate.level+"("+afterLv+")";
			var val1:int=e.pList[2];
			var exp:int =e.pList[3]
			var val2:int=e.pList[4];
			var val3:int=e.pList[5];
			var grade:int = _currBindObj.GetProperties("Grade");
			var beImpartgrade:int = _setdate?_setdate.grade:1;
			if(_currBindObj)
			{
				impartInfo =[beImpartgrade,val1,exp,val2,val3];
				if(_ui.nxtable.selected ==3)
				{
					PetAssistantLogic.getInstance().seImpartUI(impartInfo);
				}
			}
		}
		/**
		 *点击可传授的下拉列表 
		 * @param e
		 * 
		 */		
		private function onClickBox(e:NxComboBoxEvent):void
		{
			updateBeimpart(e.item.date);
			_setdate=e.item.date;
			send();
		}
		/**
		 *请求传授等级
		 * 
		 */		
		private function send():void
		{
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_REQUET_COPY_PET_RES_LEVEL,_currBindObj.GetProperties("ConfigID"),int(_setdate.configid));
		}
		/**
		 *更新被传授宠物 
		 * @param date
		 * 
		 */	
		private function updateBeimpart(date:*):void
		{
			if(_ui.nxtable.selected ==3)
				_ui.E_star2.visible=true;
			_ui.E_star2.gotoAndStop(date.grade);
			_ui.E_picMC2.scaleX =0.83;
			_ui.E_picMC2.scaleY =0.80;
			_ui.E_picMC2.source =ResourcesPath.getHeadPic(date.model);
			_ui.E_rlvLab.htmlText =date.level;
			updateImpartBtn(date);
			impartInfo[0] = date.grade
			if(_ui.nxtable.selected == 3)
				PetAssistantLogic.getInstance().seImpartUI(impartInfo);
			
		}
		private function updateImpartBtn(date:*):void
		{
			_ui.E_impartBtn.enabled=date.beimpart ==1?false:true;
			if(_currBindObj==null)return;
			if(_currBindObj.GetProperties("Impart")==0 &&date.beimpart==0)
			{
				_ui.E_impartBtn.enabled=true;
			}
			else
			{
				_ui.E_impartBtn.enabled=false;
			}

		}
	}
}
